I have tried setting the header 10 different ways and I cannot use V2; I am stuck in V1. Please help.
#set up imports
import openai
import os
import sys
# Set up the OpenAI API client
from openai import OpenAI
from typing_extensions import override
openai.api_key = os.environ['OPENAI_API_KEY']
import openai
import os
# Set up the OpenAI API key from environment
openai.api_key = os.environ['OPENAI_API_KEY']
# Ensure the beta header is set to use Assistants API v2
openai.default_headers = {"OpenAI-Beta": "assistants=v2"}
# Step 1: Create a thread to start the conversation
thread = openai.beta.threads.create()
# Step 2: Add a user message to the thread
message = openai.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content="Hello, I have a question about the assistant API."
)
# Step 3: Run the assistant on the thread using gpt-4o model and get the response
run_response = openai.beta.threads.runs.create(
thread_id=thread.id,
assistant_id="asst_sFp7klqycWhhPTlILceYzVfd", # Use your existing assistant ID
model="gpt-4o" # Use the model you prefer (gpt-4o for example)
)
# Step 4: Print the response from the assistant
print(run_response['messages'][-1]['content']) # This will print the assistant's reply
Also tried like this, no dice
from openai import OpenAI
client = OpenAI(default_headers={"OpenAI-Beta": "assistants=v1"})
Keep getting this error where it says I look at the migration docs:
Traceback (most recent call last):
File "/home/runner/OAIAssistant/main.py", line 31, in <module>
run_response = openai.beta.threads.runs.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/OAIAssistant/.pythonlibs/lib/python3.11/site-packages/openai/resources/beta/threads/runs/runs.py", line 89, in create
return self._post(
^^^^^^^^^^^
File "/home/runner/OAIAssistant/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py", line 1088, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/OAIAssistant/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py", line 853, in request
return self._request(
^^^^^^^^^^^^^^
File "/home/runner/OAIAssistant/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py", line 930, in _request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "The requested model 'gpt-4o' cannot be used with the Assistants API in v1. Follow the migration guide to upgrade to v2: https://platform.openai.com/docs/assistants/migration.", 'type': 'invalid_request_error', 'param': 'model', 'code': 'unsupported_model'}}