Skip to content
Discussion options

You must be logged in to vote

The error occurs because the response you’re getting from the API is just a plain string, not the full object that contains choices. This usually means you’re either using the wrong method or not parsing the response correctly.

In the latest OpenAI Python library, you should use .chat.completions.create() instead of.Completion.create(). Also, the returned response is a dictionary-like object, so you can safely access it like this:

from openai import OpenAI

client = OpenAI()

completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "Write a short verse explanation from https://www.alim.org/quran/."}
]
)

print(completion.choices[0].message.cont…

Replies: 4 comments 3 replies

This comment was marked as off-topic.

Comment options

You must be logged in to vote
1 reply
@Jeelislive

This comment was marked as off-topic.

Comment options

You must be logged in to vote
1 reply
@ossama-122
Comment options

Comment options

You must be logged in to vote
1 reply
@ossama-122
Comment options

Answer selected by ossama-122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ask and answer questions about GitHub features and usage Programming Help Discussions around programming languages, open source and software development
5 participants