mirror of
https://github.com/run-llama/llama-hub.git
synced 2025-08-15 04:01:32 +00:00
29 lines
687 B
Python
29 lines
687 B
Python
![]() |
"""dad_jokes reader"""
|
||
|
|
||
|
import requests
|
||
|
from typing import List
|
||
|
|
||
|
from gpt_index.readers.base import BaseReader
|
||
|
from gpt_index.readers.schema.base import Document
|
||
|
|
||
|
class DadJokesReader(BaseReader):
|
||
|
"""Dad jokes reader.
|
||
|
|
||
|
Reads a random dad joke.
|
||
|
|
||
|
"""
|
||
|
|
||
|
def _get_random_dad_joke(self):
|
||
|
response = requests.get("https://icanhazdadjoke.com/", headers={"Accept": "application/json"})
|
||
|
response.raise_for_status()
|
||
|
json_data = response.json()
|
||
|
return json_data["joke"]
|
||
|
|
||
|
def load_data(self) -> List[Document]:
|
||
|
"""Return a random dad joke.
|
||
|
|
||
|
Args:
|
||
|
None.
|
||
|
|
||
|
"""
|
||
|
return [Document(self._get_random_dad_joke())]
|