-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
I'm encountering an AttributeError when trying to use the openai.Completions attribute in my Python code. I'm using the latest version of the OpenAI Python library (version 1.47.1).
Here is the brief description of code:
import openai
input = "I love to travel"
response = sentiment_analysis(input)
print(input, "The sentiment is" , response)
When I run this code, I get the following error:
APIRemovedInV1:
You tried to access openai.Completion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.
You can run openai migrate
to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28
A detailed migration guide is available here: #742
To Reproduce
The code should successfully create a completion using the openai.Completions.create function.
Please let me know if there are any known issues or changes related to the openai.Completions attribute in the latest version of the library.
I've verified that I'm using the correct API key and that my internet connection is stable. I've also tried reinstalling the OpenAI library to ensure I'm using the latest version.
Any suggestions or workarounds would be greatly appreciated.
Code snippets
import openai
def sentiment_analysis(text):
messages = [{"Role":"system", "content":"""You are trained to analyze an detect the sentiment of the given text.
if you are unsure of answer you can say"Not sure" and recommend users to review manually."""},
{"Role":"user", "content":"""Analyze the following text and determine if the sentiment is: positive or negative.
return answer in single word as either positive or negative: {text}"""}]
response = openai.Completion.create(
engine="text-davinci-003",
messages=messages,
max_tokens=1,
n=1,
stop=None,
temperature=0)
sentiment = response.choices[0].message.content.strip().lower()
return sentiment
input = "I love to travel"
response = sentiment_analysis(input)
print(input, "The sentiment is" , response)
OS
windows
Python version
3.12.6
Library version
1.47.1