ai_api is a simple framework for building your own ChatGPT plugins using your own APIs. Inspired by the python Flask framework, ai_api provides a simple way to register API functions with ChatGPT, using your existng documentation to train the AI on how to call your data.
from ai_api import AiApi
app = AiApi()
@app.register_api()
def is_website_up(website: str):
'''
Tests if a website up and running
Args:
website (str): The full url of the website.
Returns:
Boolean: true of false if the website is up (true) or down (false)
Code Example:
website = "https://google.com"
status = is_website_up(website)
'''
try:
resp = requests.get(website, timeout=5)
resp.raise_for_status()
return True
except:
return False
app.execute_query("Is stackoverflow down right now?")
# AI >> It is working for me.
As we have seen, good documentation is actually a great source of prompt engineering for an AI to understand how to interact with your custom APIs. We build on this by generating prompts based on your own docs and then help an AI know when to call them.
ai_api can be installed via pip:
pip install ai_api
- Import AiApi
from ai_api import AiApi
- Configure and instantiate the AiApi object:
app = AiApi(openai_api_key=open_ai_key, LOG_LEVEL="DEBUG")
- Register your APIs using the register_api decorator:
@app.register_api()
def my_api_function(arg1, arg2):
# Do something with arg1 and arg2
return result
- As the LLM a question:
response = app.execute_query("What is the answer to my question?")
There are 2 examples in the examples directory in this repo. The first example lookus up SEC filings types and another where we generate a random number.
ai_api comes with a suite of tests that can be run using pytest. To run the tests, first install pytest:
pip install pytest
Then run the tests:
pytest
If you find a bug or have a feature request, please open an issue on GitHub. If you would like to contribute to the project, please fork the repository, make your changes, and submit a pull request. Please make sure all tests are passing :)