Embedchain now supports OpenAI Assistants API which allows you to build AI assistants within your own applications. An Assistant has instructions and can leverage models, tools, and knowledge to respond to user queries.At a high level, an integration of the Assistants API has the following flow:
Create an Assistant in the API by defining custom instructions and picking a model
Create a Thread when a user starts a conversation
Add Messages to the Thread as the user ask questions
Run the Assistant on the Thread to trigger responses. This automatically calls the relevant tools.
Creating an OpenAI Assistant using Embedchain is very simple 3 step process.
Make sure that you have OPENAI_API_KEY set in the environment variable.
Initialize
Copy
Ask AI
from embedchain.store.assistants import OpenAIAssistantassistant = OpenAIAssistant( name="OpenAI DevDay Assistant", instructions="You are an organizer of OpenAI DevDay",)
If you want to use the existing assistant, you can do something like this:
Initialize
Copy
Ask AI
# Load an assistant and create a new threadassistant = OpenAIAssistant(assistant_id="asst_xxx")# Load a specific thread for an assistantassistant = OpenAIAssistant(assistant_id="asst_xxx", thread_id="thread_xxx")
You can add any custom data source that is supported by Embedchain. Else, you can directly pass the file path on your local system and Embedchain propagates it to OpenAI Assistant.
assistant.chat("How much OpenAI credits were offered to attendees during OpenAI DevDay?")# Response: 'Every attendee of OpenAI DevDay 2023 was offered $500 in OpenAI credits.'
You can try it out yourself using the following Google Colab notebook: