You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0
any fixes?
I tried to follow every step and setup the environment and did everything that is needed.
this is the part of the code i has noticed trouble with:
openai.api_key = os.getenv(“OPENAI_API_KEY”)
def get_answer(question):
“”"
Fetches an answer from OpenAI based on the provided question.
“”"
try:
response = openai.ChatCompletion.create(
model=“gpt-3.5-turbo”, # Use an appropriate model
messages=[
{“role”: “system”, “content”: “You are a helpful assistant.”},
{“role”: “user”, “content”: question}
],
max_tokens=100,
n=1,
stop=None,
temperature=1.0,
request_timeout=30 # Set the request timeout here
)
# Access the response content using Pydantic models
answer = response.choices[0].message[“content”].strip()
return answer
except Exception as e:
print(f"An error occurred while fetching an answer from OpenAI: {e}")
return “Unable to fetch answer.”
keeps getting a connection error while trying to fetch answer.
“Generated Answer: Unable to fetch answer.”
probably the problematic part of my script:
openai.api_key = os.getenv(“OPENAI_API_KEY”)
def get_answer(question):
“”"
Fetches an answer from OpenAI based on the provided question.
“”"
try:
completion = client.chat.completions.create(
model=“gpt-3.5-turbo”, # Use an appropriate model
messages=[
{“role”: “system”, “content”: “You are a helpful assistant.”},
{“role”: “user”, “content”: question}
],
max_tokens=100,
n=1,
stop=None,
temperature=1.0,
timeout=30 # Added timeout parameter correctly here
)
# Access the response content
answer = completion.choices[0].message[‘content’]
return answer
except Exception as e:
print(f"An error occurred while fetching an answer from OpenAI: {e}")
return “Unable to fetch answer.”
Specify the path to tesseract executable if it’s not in your PATH