Ok, ive seen this all over. But never see a clear resolution. Here is the code im using.
import openai
Set the API key
openai.api_key = OPENAI_API_KEY
Test an OpenAI API call
def summarize_text(text):
response = openai.ChatCompletion.create(
model=“gpt-4”,
messages=[
{“role”: “system”, “content”: “Summarize the following text.”},
{“role”: “user”, “content”: text},
],
)
return response[“choices”][0][“message”][“content”]
Test summarization
try:
summary = summarize_text(“This is a test text for summarization.”)
print(“Summary:”, summary)
except Exception as e:
print(“Error with OpenAI API:”, e)
And here is the error i keep getting no matter what platform im on or changes i make from the suggestions.
Access token generated successfully:
Error with OpenAI API:
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.
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: v1.0.0 Migration Guide · openai/openai-python · Discussion #742 · GitHub
I am using GPT 4, and version 1.57 so i have the most up to date items. Please help, im new and have no clue and im on week 2 of trying to figure this out.