OpenAI Assistants Example
Learn how to use OpenAI Assistants API with AgentOps
View Notebook on Github
Assistants API with AgentOps
This guide shows how to monitor and track OpenAI’s Assistants API using AgentOps. The Assistants API is a stateful evolution of the Chat Completions API for creating assistant-like experiences with powerful tools like Code Interpreter and Retrieval.
Installation
Setup
Import the necessary libraries:
Set up your API keys:
Initialize AgentOps at the beginning of your application:
Creating an Assistant
Create a Math Tutor assistant:
Working with Threads
Create a new thread to hold the conversation:
Add a message to the thread:
Running an Assistant
Create a Run to get a completion from the Assistant:
Wait for the Run to complete:
Retrieving Messages
List the messages in the thread:
Continue the conversation with a follow-up question:
Complete Example Function
Here’s a practical example of implementing Assistants API with helper functions:
Using Tools with Assistants
Code Interpreter
Enable Code Interpreter for your Assistant:
Test it with a coding task:
Function Calling
Define a custom function for your Assistant:
Implement the function on your end:
Ending the Session
End the AgentOps session when done:
Further Reading
Check out more advanced examples like Multi-Agent integration.