Hello - i currently have this working assistant solution - but not i get several deprecation wargning:
C:\DEVNEU\Fiverr2025\TRY\seagullandshark\test.py:68: DeprecationWarning: The Assistants API is deprecated in favor of the Responses API
thread = client.beta.threads.create()
Preparing question
C:\DEVNEU\Fiverr2025\TRY\seagullandshark\test.py:70: DeprecationWarning: The Assistants API is deprecated in favor of the Responses API
results = client.beta.threads.messages.create(
Running for answer
C:\DEVNEU\Fiverr2025\TRY\seagullandshark\test.py:76: DeprecationWarning: The Assistants API is deprecated in favor of the Responses API
run = client.beta.threads.runs.create (
C:\DEVNEU\Fiverr2025\TRY\seagullandshark\test.py:81: DeprecationWarning: The Assistants API is deprecated in favor of the Responses API
run = client.beta.threads.runs.retrieve (
C:\DEVNEU\Fiverr2025\TRY\seagullandshark\test.py:87: DeprecationWarning: The Assistants API is deprecated in favor of the Responses API
results = client.beta.threads.messages.list(
Find attached the code which i am using:
import os, sys
import time
from dotenv import load_dotenv
from openai import OpenAI
from pydantic import BaseModel
import json
from typing import Listpath = os.path.abspath(os.path.dirname(sys.argv[0]))
class ArticleSummary(BaseModel):
buyerName: str
purchasePercentInterest: str
purchasePrice: strclass Messages(BaseModel):
messages: List[ArticleSummary]fn = os.path.join(path, “.env”)
load_dotenv(fn)
CHATGPT_API_KEY = os.environ.get(“CHATGPT_API_KEY”)
client = OpenAI(api_key = CHATGPT_API_KEY)fn = os.path.join(path, “prompt.txt”)
with open(fn, encoding=“utf-8”, errors=“ignore”) as f:
lines = f.read().splitlines()
questionParse = “\n”.join(lines)vector_store = client.vector_stores.create(name=“File”)
pdf1 = os.path.join(path, “inpPA.pdf”)
pdf2 = os.path.join(path, “inpPQ.pdf”)file_paths = [pdf1, pdf2]
file_streams = [open(path, “rb”) for path in file_paths]
file_batch = client.vector_stores.file_batches.upload_and_poll(
vector_store_id=vector_store.id, files=file_streams
)
print(file_batch.status)
print(file_batch.file_counts)print(f"Preparing assistant for file")
assistant = client.beta.assistants.create(
name=“Document Analyse Assistant”,
instructions=“You are a machine learning researcher, answer questions about the provided pdf
file”,
model = “gpt-4o”,
tools = [{“type”: “file_search”}],
response_format={
“type”: “json_schema”,
“json_schema”: {
“name”: “test_schema”,
“schema”: Messages.model_json_schema()
}
}
)
assistant = client.beta.assistants.update(
assistant_id=assistant.id,
tool_resources={“file_search”: {“vector_store_ids”: [vector_store.id]}},
)print(f"Preparing thread")
thread = client.beta.threads.create()
print(f"Preparing question")
results = client.beta.threads.messages.create(
thread_id = thread.id,
role = “user”,
content = questionParse
)print(f"Running for answer")
run = client.beta.threads.runs.create (
thread_id = thread.id,
assistant_id = assistant.id
)while run.status not in [“completed”, “failed”]:
run = client.beta.threads.runs.retrieve (
thread_id = thread.id,
run_id = run.id
)if run.status == “completed”:
results = client.beta.threads.messages.list(
thread_id=thread.id
)
resultAnswer = results.data[0].content[0].text.valuetry:
resultAnswer = json.loads(resultAnswer)
except:
print(f"No output - try again…")
time.sleep(3)with open(‘data.json’, ‘w’, encoding=‘utf-8’) as f:
json.dump(resultAnswer, f, ensure_ascii=False, indent=4)
print(resultAnswer)if run.status == “failed”:
print(run.last_error.code)
print(run.last_error.message)
How can i change this code so its running with the new version from openai without deprecation warnings.