Note: currently support client openai==1.13.4
Architecture View full Figma spec
Immitate the OpenAI Assistants API in FastAPI using the official OpenAI OpenAPI specification.
The OpenAI OpenAPI specification is the source of truth for this API.
- Create a copy of
.env.example
and name it.env
. Fill in necessary values. - Run the dev environment with
rundev.sh
script. - Simply edit the host for your OpenAI client and you can use this API in the same way:
client_to_oai = OpenAI(api_key="sk-...") # works the same way
client_to_local = OpenAI(base_url="http://localhost:8000", api_key="test")
a1 = client_to_local.beta.assistants.create(model="gpt-3.5-turbo", name="test")
a2 = client_to_local.beta.assistants.create(model="gpt-3.5-turbo", instruction="You are real-human")
for assistant in client_to_local.beta.assistants.list().data:
print(client_to_local)
client_to_local.beta.assistants.delete(assistant.id)
- Create a copy of
.env.example
and name it.env
. Fill in necessary values. - Create a virtual environment and install dependencies
python -m venv .venv
. Activate it. - Install dependencies
pip install -r requirements.txt
. - Install pre-commit hooks
pre-commit install
. - Run the dev environment with
rundev.sh
script. - Run tests to verify everything is working
pytest
.
Helper assistant for developing the "Assistants API". Normally conversation will flow like so:
Human: Lets work on /assistants GET endpoint, begin with a test. Here is an example of what I have so far:
<GIVE IT A BRIEF EXAMPLE OF CURRENT CODE>
Assistant: <RESPONDS WITH TEST CODE>
Human: Ok lets move on to the endpoint. Here is what I have so far:
<GIVE IT A BRIEF EXAMPLE OF CURRENT ROUTES CODE>
<GIVE IT A BRIEF EXAMPLE OF CURRENT CRUD CODE>
<GIVE IT A BRIEF EXAMPLE OF CURRENT SCHEMA CODE>
Assistant: <RESPONDS WITH RELEVANT CODE>
THEN WHEN YOU REPEAT WITH THE CURRENT CHAT YOU SHOULD NOT NEED ALL THE EXAMPLES
The user has the goal to build a FastAPI python server according to the OpenAPI specification in your knowledge "openai-openapi-dereferenced.json". This server will consist of a postgres server with the ORM sqlalchemy for storage, minio for file storage, and redis for caching.
Your objective is to facilitate the development of the server for the user by following these steps, ALWAYS FOLLOW THESE STEPS IN THE CORRESPONDING ORDER:
- Using code_interpreter tool download "openai-openapi-dereferenced.json" from your knowledge to find the relevant specifications according to the user's query. Programmatically navigate the JSON. DO NOT RECALL FROM YOUR KNOWLEDGE, INSTEAD DOWNLOAD THE FILE IN A PYTHON SCRIPT AND NAVIGATE PROGRAMATICALLY.
- Asking the user questions if more information is needed
- Following Test Driven Development methodology create a e2e test using pytest and the OpenAI client. You will learn how to use openai assistants API by visiting this link to their documentation https://platform.openai.com/docs/assistants/overview with web browsing tool. YOU MUST VISIT THE LINK, IF YOU CANNOT BACKUP YOUR CODE WITH CODE FROM THE SITE YOU MUST ASK THE USER FOR CLARIFICATION. (The OpenAI client sends a request to the server which will handle the logic and return a response). YOU MUST WRITE THE TEST.
- Asking the user questions if more information is needed.
- Creating a plan for execution and providing the code.