|
2 | 2 |
|
3 | 3 | It's an API that generates jokes! The in-built ones are programming jokes, but using the `/generate-joke` route, you can generate any joke you would like using AI!
|
4 | 4 |
|
| 5 | +Add a little sprinkle of humor into any project easily! This is perfect for inserting a little pun on your homepage, showing users a personalized joke while they wait for something to load, or showing our joke of the day in your footer! |
| 6 | + |
5 | 7 | ## Routes
|
6 | 8 |
|
| 9 | +Note: better documentation is available on the website. |
| 10 | + |
7 | 11 | - `GET /` - Returns this HTML page containing a random joke and the API documentation.
|
8 | 12 | - `POST /` - Returns a random joke in JSON format.
|
9 | 13 | - `POST /puns` - Returns a list of random jokes in JSON format. If number is not given, returns all jokes.
|
10 | 14 | - `POST /joke-of-the-day` - Returns a random joke in JSON format. If date is given, it fetches the joke of the day for that date. If date is not given, it fetches the joke of the day for today.
|
11 | 15 | - `POST /generate-joke` - Returns a random joke in JSON format. If prompt is given, it generates a joke relating to the prompt. If prompt is not given, it generates a random programming related joke. Uses the Llama3.2-3b model from Meta and is hosted on LeptonAI.
|
12 | 16 | - `POST /search-jokes` - Returns a list of jokes in JSON format that contain the query. If limit is given, it returns at most limit jokes. If limit is not given, it returns at most 10 jokes.
|
13 | 17 | - `POST /get-jokes-by-tag` - Returns a list of jokes in JSON format that contain the tag.
|
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +**I highly recommend using the pre-hosted API rather than self-hosting.** |
| 22 | + |
| 23 | +Clone the repo and install dependencies: |
| 24 | + |
| 25 | +``` |
| 26 | +git clone https://github.com/AdamEXu/JokeAPI.git |
| 27 | +cd JokeAPI |
| 28 | +python3 -m pip install -r requirements.txt |
| 29 | +``` |
| 30 | + |
| 31 | +If you would like to use the generate joke feature, you'll have to grab a **free** API key from [lepton.ai](https://lepton.ai/). Then set the environment variable: |
| 32 | + |
| 33 | +``` |
| 34 | +export LEPTON_API_TOKEN="YOUR_LEPTON_API_KEY_WHATEVER_BLAH_BLAH_BLAH_YAY" |
| 35 | +``` |
| 36 | + |
| 37 | +If you are running this on your local machine where port 80 will most likely be protected, set the debug flag. |
| 38 | + |
| 39 | +``` |
| 40 | +export DEBUG=TRUE |
| 41 | +``` |
| 42 | + |
| 43 | +Now, you can run the server: |
| 44 | + |
| 45 | +``` |
| 46 | +python app.py |
| 47 | +``` |
| 48 | + |
| 49 | +Now, go to [localhost](http://localhost/), or [localhost:8080](http://localhost:8080/) if you have the debug flag on. There will be instructions on how to use the API there. |
| 50 | + |
| 51 | +## Or... Use my hosted API! |
| 52 | + |
| 53 | +I hosted the API on two places: |
| 54 | + |
| 55 | +**Vercel:** [raspapi-jokeapi.vercel.app](https://raspapi-jokeapi.vercel.app/) |
| 56 | +**Nest:** [raspapi-example.adamthegreat.hackclub.app](https://raspapi-example.adamthegreat.hackclub.app/) |
| 57 | + |
| 58 | +Note that both of these may stop working at any time. The Vercel hosted one will likely be more reliable (nest outages \*cough\*) |
| 59 | + |
| 60 | +Use the API as much as you want in your projects to add a dash of humor! |
0 commit comments