Last week I put together a notebook to quickly compare gpt4 vision to a file search assistant. I had no issues following the example in docs (https://platform.openai.com/docs/assistants/tools/file-search) and determined for the application vision had no obvious benefit.
I’m trying to re-run the notebook today and keep getting a “NotFoundError”.
I can instantiate a client and make a completions call, but cannot create an assistant.
I’m using the same env, no changes to venv and am at a loss. Googling suggests assistants api might just be unreliable but nothing for this issue specifically.
I’m using API version 2024-10-21 but have tried multiple.
Can anyone assist?
from openai import OpenAI
from dotenv import load_dotenv
import os
load_dotenv(override=True)
openai_model=os.getenv("OPENAI_MODEL")
openai_endpoint=os.getenv("OPENAI_API_BASE_URL")
openai_api_key= os.getenv("OPENAI_API_KEY")
api_version= os.getenv("AGENT_OPENAI_API")
openai_client = OpenAI(
base_url=openai_endpoint,
api_key=openai_api_key,
)
response = openai_client.chat.completions.create(
model='gpt-4o',
messages = [
{"role":"user","content":"tell me a joke in spanish"}
],
)
response.choices[0].message.content
results in:
‘¡Claro! Aquí tienes un chiste en español:\n\n¿Por qué los pájaros no usan Facebook?\n\nPorque ya tienen Twitter.’
but I can’t use the client to create an assistant, even using the doc example
assistant = openai_client.beta.assistants.create(
name="Financial Analyst Assistant",
instructions="You are an expert financial analyst. Use you knowledge base to answer questions about audited financial statements.",
model="gpt-4o",
tools=[{"type": "file_search"}],
)
What is “not found” is that you are sending the API request off to nowhere’sville by messing with the internal parameters.
Try starting your code like this, with self-reminders:
from openai import OpenAI # Import OpenAI SDK
# Initialize OpenAI client without dotenv
# No need to set API keys manually if OPENAI_API_KEY is
# already in the runtime environment
client = OpenAI()
then all the parameters you might want to configure during assistant creation.
# Create a new assistant with specified parameters
my_assistant = client.beta.assistants.create(
model="gpt-4o-2024-11-20", # Model version to use
name="helpbot", # Name of the assistant
instructions="You are a helpful assistant. Your app "
"creator uploaded knowledge files.",
tools=[
{"type": "file_search", "file_search":
{"max_num_results": 12}} # Configure max chunks
],
tool_resources={
"code_interpreter": {"file_ids": []},
"file_search": {"vector_store_ids":
["vs_6700c8e3b081918b53fdaea2b"]} # your vector store
},
temperature=1, # Controls randomness (1 is moderate)
top_p=0.2, # Nucleus sampling (focuses on top 20%)
response_format={"type": "text"}, # only text with file search
reasoning_effort=None # Clears reasoning effort for other models
)
# Print assistant ID for reference
print(f"Assistant created with ID: {my_assistant.id}")
Thank you for your quick response but I have not been able to resolve the issue.
I first tried modifying the existing notebook and saw no changes. Then I created a new project in a new repo, created a fresh venv with only OpenAI, and started a new notebook. I tried the following setup as recommended
from openai import OpenAI
import os
os.environ['OPENAI_API_KEY'] = redacted
os.environ['OPENAI_BASE_URL'] = redacted
client = OpenAI()
completions api works as expected
response = client.chat.completions.create(
model='gpt-4o',
messages = [
{"role":"user","content":"tell me a joke in spanish"}
],
)
response.choices[0].message.content
still gives
‘Claro, aquí tienes un chiste en español:\n\n¿Por qué los pájaros no usan Facebook?\n\nPorque ya tienen Twitter.’
but trying to create an assistant has the same error
my_assistant = client.beta.assistants.create(
model="gpt-4o-2024-11-20", # Model version to use
name="helpbot", # Name of the assistant
instructions="You are a helpful assistant. Your app "
"creator uploaded knowledge files.",
tools=[
{"type": "file_search", "file_search":
{"max_num_results": 12}} # Configure max chunks
],
tool_resources={
"code_interpreter": {"file_ids": []},
"file_search": {"vector_store_ids":
["vs_6700c8e3b081918b53fdaea2b"]} # your vector store
},
temperature=1, # Controls randomness (1 is moderate)
top_p=0.2, # Nucleus sampling (focuses on top 20%)
response_format={"type": "text"}, # only text with file search
reasoning_effort=None # Clears reasoning effort for other models
)
# Print assistant ID for reference
print(f"Assistant created with ID: {my_assistant.id}")
#and
assistant = client.beta.assistants.create(
name="Financial Analyst Assistant",
instructions="You are an expert financial analyst. Use you knowledge base to answer questions about audited financial statements.",
model="gpt-4o",
tools=[{"type": "file_search"}],
)
This usage of the correct version and URL of assistants also requires that the OpenAI Python library be up to date. Install and use the most recent version.
>>> import openai
>>> openai.__version__
'1.61.0'
Also, in a notebook, the previous state of code cell actions, such as setting objects like the client, will be maintained unless you re-run the whole notebook, or close it and open it again.
That should at least get you to a failure error message on the fake vector store ID as the reason.
response = client.chat.completions.create(
model='gpt-4o',
messages = [
{"role":"user","content":"tell me a joke in spanish"}
],
)
response.choices[0].message.content
assistant = client.beta.assistants.create(
name="Financial Analyst Assistant",
instructions="You are an expert financial analyst. Use you knowledge base to answer questions about audited financial statements.",
model="gpt-4o",
tools=[{"type": "file_search"}],
)
As with previous tests the chat completions works as expected and the assistant gives the same error:
Unfortunately I am required to provide a base URL for my orgs dedicated OpenAI instance. I have some flexibility while developing and testing but ultimately i needs to use this.
Prior to getting OpenAI working last week I tried using Azure. I was not able to get it to work despite using a supported model (gpt-4o) in supported regions (tried East US and West US).
Using the same syntax as above (but with Azure client) results in