The error you’re encountering indicates that ChatCompletion
is not a subscriptable object, meaning you can’t use indexing ([]
) directly on it. It seems like the response object is not a dictionary, but an instance of a ChatCompletion
class.
When dealing with a class instance, you would typically access its attributes using dot notation. If you are using the OpenAI Python client, the attributes of the ChatCompletion
object would be accessed accordingly. However, the output structure seems to suggest that it should be possible to subscript it if it were a dictionary.
Here is how I fixed this:
# Assuming 'response' is an instance of a ChatCompletion or similar class
message_content = response.choices[0].message.content
print(message_content)
Using the period instead of the bracket worked.