In the example below, the first part, which uses the completion API succeeds. The second part, which attempts to use the assistant API, with the same endpoint, API key and deployment name, throws a “resource not found” exception. What am I doing wrong here? How do I use the Assistant API with OpenAI Azure?
import os
import dotenv
from openai import AzureOpenAI
dotenv.load_dotenv()
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version="2024-02-01",
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
)
deployment_name=os.getenv("AZURE_DEPLOYMENT_NAME")
print("Deployment name:", deployment_name)
start_phrase = 'Write a tagline for an ice cream shop. '
#completion API - succeeds
response = client.chat.completions.create(
model=deployment_name,
messages = [{"role":"system", "content":start_phrase}])
print(response.choices[0].message.content)
# assistant API - errors out with "resource not found"
assistant = client.beta.assistants.create(
name = "Test OpenAI Azure Assistant",
instructions="You are a helpful assistant.",
model=deployment_name
)