I am now getting an error that flags my Get_completion and openai.chatcompletion code lines stating, "You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0
I queried ChatGPT4 for the correct syntax for this error and tried it, but still get the error below (in both GPT 3.5 and GPT 4)
Case Example
def get_completion(prompt, model=“gpt-3.5-turbo”):
messages = [{“role”: “user”, “content”: prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0, # this is the degree of randomness of the model’s output
)
return response.choices[0].message[“content”]
No error generated running code snippet above
My prompt to run
prompt = f"“”
Generate a list of three made-up book titles along
with their authors and genres.
Provide them in JSON format with the following keys:
book_id, title, author, genre.
“”"
response = get_completion(prompt)
print(response)
The error response
APIRemovedInV1 Traceback (most recent call last)
Cell In[43], line 7
1 prompt = f"“”
2 Generate a list of three made-up book titles along
3 with their authors and genres.
4 Provide them in JSON format with the following keys:
5 book_id, title, author, genre.
6 “”"
----> 7 response = get_completion(prompt)
8 print(response)
Cell In[42], line 3, in get_completion(prompt, model)
1 def get_completion(prompt, model=“gpt-3.5-turbo”):
2 messages = [{“role”: “user”, “content”: prompt}]
----> 3 response = openai.ChatCompletion.create(
4 model=model,
5 messages=messages,
6 temperature=0, # this is the degree of randomness of the model’s output
7 )
8 return response.choices[0].message[“content”]
File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\openai\lib_old_api.py:39, in APIRemovedInV1Proxy.call(self, *_args, **_kwargs)
38 def call(self, *_args: Any, **_kwargs: Any) → Any:
—> 39 raise APIRemovedInV1(symbol=self._symbol)
APIRemovedInV1:
*You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at GitHub - openai/openai-python: The official Python library for the OpenAI API for the API.