Gives an error when receiving a gpt 4 vision photo

in getattr
raise AttributeError(f’{type(self).name!r} object has no attribute {item!r}') from exc
AttributeError: ‘Choice’ object has no attribute ‘text’

Function for getting image URL from VK

def get_vk_photo_url(photo_object):
# Find the photo with the largest size
largest_photo = max(photo_object[‘sizes’], key=lambda size: size[‘width’] * size[‘height’])
# Get the direct URL
direct_url = largest_photo[‘url’]
# Print the obtained direct URL
print(f"Direct link to the image: {direct_url}")
# Return the direct URL
return direct_url

Function for sending a request to OpenAI

def get_openai_response(image_url):
response = openai_client.chat.completions.create(
model=“gpt-4-vision-preview”,
messages=[
{
“role”: “user”,
“content”: [
{“type”: “text”, “text”: “What’s in this image?”},
{
“type”: “image_url”,
“image_url”: {
“url”: image_url,
},
},
],
}
],
max_tokens=300,
)
return response.choices[0].text

Main loop for VK long polling

for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
message = vk.messages.getById(message_ids=event.message_id)[‘items’][0]
attachments = message.get(‘attachments’)
if attachments:
for attachment in attachments:
if attachment[‘type’] == ‘photo’:
# Get the image URL
image_url = get_vk_photo_url(attachment[‘photo’])
# Get the response from OpenAI
openai_response = get_openai_response(image_url)
# Error handling and sending the response to VK user
if ‘error’ in openai_response:
error_message = openai_response[‘error’][‘message’]
print(“Error from OpenAI:”, error_message)
else:
response_content = openai_response[‘choices’][0][‘message’][‘content’]
vk.messages.send(
user_id=event.user_id,
message=response_content,
random_id=get_random_id()
)