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",#also tried with 2024-02-15-preview and 2024.05.01-preview
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
)
No dude, it’s kinda tricky in terms of terminology I guess:
you need to first create an assistants deployment on azure - that is like the runtime in which your assistants will run
once you created that assistants deployment, you should be able to deploy/ create assistants within that deployment. (not instances of assistants! assistants.)
then within that assistants deployment, you have created an assistant, whithin which you can then create a thread, to which you can then add a message…
I think you’re skipping a couple of initial steps, so it’s gonna give you the not found errors.
Assistants on azure have always been a bit iffy… I’d recommend trying to get it to work on OAI first if it’s your first time, and then move to azure…
assistant = client.beta.assistants.create(
name=“Data Visualization”,
instructions=f"You are a helpful AI assistant who makes interesting visualizations based on data."
f"You have access to a sandboxed environment for writing and testing code."
f"When you are asked to create a visualization you should follow these steps:"
f"1. Write the code."
f"2. Anytime you write new code display a preview of the code to show your work."
f"3. Run the code to confirm that it runs."
f"4. If the code is successful display the visualization."
f"5. If the code is unsuccessful display the error message and try to revise the code and rerun going through the steps from above again.",
tools=[{“type”: “code_interpreter”}],
model=“gpt-4-1106-preview” #You must replace this value with the deployment name for your model.
)