Hello, When making assistant I am getting a failed status, so I tried to get details of this error, but couldn’t,
Starting assistant run…
Assistant run started. Run ID: run_ldxB03FREaSuY57KhJxVGegb
Run status: in_progress
Run status: in_progress
Run status: in_progress
Run status: in_progress
Run status: failed
Run failed with error: No failure details available
in
OPEN_AI_API_KEY = os.getenv("OPEN_AI_API_KEY")
client = OpenAI(api_key=OPEN_AI_API_KEY)
def run_assistant(thread):
#Retrieve the Assistant ID from shelve (or wherever it's stored)
with shelve.open("assistant_db") as assistant_shelf:
assistant_id = assistant_shelf.get('assistant_id', None)
if not assistant_id:
raise ValueError("No assistant ID found. Please create an assistant first.")
print("Starting assistant run...")
# Run the assistant
run = client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant_id,
)
print(f"Assistant run started. Run ID: {run.id}")
# Timeout mechanism to avoid infinite wait
start_time = time.time()
timeout = 60
while run.status != "completed":
if time.time() - start_time > timeout:
raise TimeoutError("Assistant response took too long.")
time.sleep(1)
try:
run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
print(f"Run status: {run.status}")
if run.status == "failed":
failure_error = getattr(run, 'failure_message', "No failure details available")
print(f"Run failed with error: {failure_error}")
except Exception as e:
print(f"Error retrieving run status: {e}")
print("Assistant run completed.")
try:
# Retrieve the Messages
messages = client.beta.threads.messages.list(thread_id=thread.id)
new_message = messages.data[0].content[0].text.value
print(f"Generated message: {new_message}")
except Exception as e:
print(f"Error retrieving message: {e}")
return new_message
Can you spot the problem?
Thank you in advance