invalid_request_error on Azure Assistants API.
Barnabas Vicsay
5
Reputation points
I am getting an invalid_request_error on Azures assistants API on code that was basically basted from docs and modified only slightly to fit the codebase. The full error is: openai.NotFoundError: Error code: 404 - {'error': {'message': 'Invalid URL (POST /v1/assistants)', 'type': 'invalid_request_error', 'param': None, 'code': None}}
import os
import time
import json
from openai import AzureOpenAI
client = AzureOpenAI(
api_key=os.getenv("key"),
api_version="2024-02-15-preview",
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
)
# Create an assistant
assistant = client.beta.assistants.create(
name="Math Assist",
instructions="You are an AI assistant that can write code to help answer math questions.",
tools=[{"type": "code_interpreter"}],
model="gpt-3-5-turbo" #You must replace this value with the deployment name for your model.
)
# Create a thread
thread = client.beta.threads.create()
# Add a user question to the thread
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 the thread
run = client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id,
)
# Retrieve the status of the run
run = client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id
)
status = run.status
# Wait till the assistant has responded
while status not in ["completed", "cancelled", "expired", "failed"]:
time.sleep(5)
run = client.beta.threads.runs.retrieve(thread_id=thread.id,run_id=run.id)
status = run.status
messages = client.beta.threads.messages.list(
thread_id=thread.id
)
print(messages.model_dump_json(indent=2))