UNPKG

roastify

Version:

A Node.js library that generates sarcastic and roast-style responses for API failures using OpenAI.

75 lines (58 loc) β€’ 2.57 kB
# Roastify Roastify is a Node.js middleware that returns sarcastic and roast-style responses for API failures using OpenAI. Instead of boring error messages like "Invalid username or password," Roastify delivers witty burns to keep your API responses entertaining. ## Features - πŸ”₯ **Generates dynamic roast responses** using OpenAI. - πŸ˜† **Customizable failure types** (authentication, validation, general errors, etc.). - πŸš€ **Middleware for Express.js** to make integration seamless. - πŸ”‘ **Caller provides their own OpenAI API key** (no key stored in the library). ## Installation ```sh npm install roastify ``` ## Usage ### Basic Express Setup ```javascript const express = require("express"); const { roastMiddleware } = require("roastify"); const app = express(); app.use(roastMiddleware("your-openai-api-key")); app.get("/fail", async (req, res) => { await res.sendRoast(); }); app.listen(3000, () => console.log("Server running on port 3000")); ``` ### Custom Error Types You can pass a **failure type** to get different styles of roast messages. ```javascript app.get("/auth-fail", async (req, res) => { await res.sendRoast("authentication"); }); app.get("/validation-fail", async (req, res) => { await res.sendRoast("validation"); }); ``` ## How It Works 1. **Roastify intercepts failed requests** and sends a sarcastic response instead of a standard error message. 2. **Responses are dynamically generated** using OpenAI’s API to keep them fresh and unpredictable. 3. **The caller must provide an OpenAI API key** when initializing the middleware. ## Example Responses | Failure Type | Example Roast Response | |---------------|----------------------| | Authentication | "Oh wow, another victim of their own terrible memory. Try again, genius." | | Validation | "You had ONE job: enter valid data. And you still messed it up." | | General | "Well, that didn't go as planned. But hey, at least you're consistent at failing!" | ## Configuration - **API Key:** You must pass an OpenAI API key when initializing the middleware. - **Max Tokens:** Limited to 30 for concise responses. - **Temperature:** Set to 0.8 for creative but controlled roasts. ## Error Handling If OpenAI fails to generate a response, Roastify falls back to a default roast: ```json { "message": "Even the AI couldn't handle this request. That's how bad it is." } ``` ## License MIT License --- 😈 **Turn your boring API errors into brutal roasts with Roastify!** πŸ”₯