Hi, Im trying out the example from OpenAI documentation but I am getting failed only. Here is the code I am using:
import os
from openai import OpenAI
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
client = OpenAI(
api_key = os.getenv("OPENAI_API_KEY"),
)
assistant = client.beta.assistants.create(
name="Math Tutor",
instructions="You are a personal math tutor. Write and run code to answer math questions.",
tools=[{"type": "code_interpreter"}],
model="gpt-3.5-turbo-0125",
)
thread = client.beta.threads.create()
message = client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content="I need to solve the equation `3x + 11 = 14`. Can you help me?"
)
run = client.beta.threads.runs.create_and_poll(
thread_id=thread.id,
assistant_id=assistant.id,
instructions="Please address the user as Jane Doe. The user has a premium account."
)
# Wait for the run to complete and get the response
while run.status not in ["completed", "failed"]:
run = client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id
)
# If the run completed successfully, get the latest messages
if run.status == "completed":
messages = client.beta.threads.messages.list(
thread_id=thread.id
)
print(messages)
if run.status == "failed":
print("F")