Hello everyone,
I’m currently working on a project where I’m using the OpenAI API to generate responses based on user input. I’m using the openai.ChatCompletion.create method to send messages to the API and receive a response.
The issue I’m encountering is when I try to access the ‘choices’ attribute from the response object. Here’s the relevant part of my code:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": system_message},
{"role": "user", "content": user_message}
]
)
print(response)
analysis = response.choices[0].message.content.strip()
When I run this code, I get an error message saying “member choice is unknown”. However, when I print the response object, I can see that it includes a ‘choices’ field.
Here are the solutions I’ve tried so far:
-
Accessing the ‘choices’ field with dictionary-like indexing (response[‘choices’]). This didn’t work because the response object is not a dictionary.
-
Checking the version of the OpenAI Python client library I’m using. I’m using the latest version, so this doesn’t seem to be the issue.
-
Using the .choices attribute to access the ‘choices’ field (response.choices). This is the method that’s causing the “member choice is unknown” error.
I’m not sure what else to try at this point. I would appreciate any suggestions on how to resolve this issue. Specifically, I’m looking for a way to access the ‘choices’ field from the response object without encountering the “member choice is unknown” error.
Thank you in advance for your help!