I’m encountering an error when using GPT-4o that I haven’t run into with GPT-4-turbo. When I switched over, I got this error:
Error code: 400 - {‘error’: {‘message’: “Invalid ‘messages[4]’. Image URLs are only allowed for messages with role ‘user’, but this message with role ‘system’ contains an image URL.”, ‘type’: ‘invalid_request_error’, ‘param’: ‘messages[4]’, ‘code’: ‘invalid_value’}}
Seems like GPT-4o doesn’t allow image URLs in system messages, while GPT-4-turbo doesn’t have a problem with it. Are there any workarounds for this, or plans to update GPT-4o to allow images in system messages?
So then assistant / system cannot pass in imageURLs? However according to gpt-4o vision documentation: " Images can be passed in the user , system and assistant messages" https://platform.openai.com/docs/guides/vision
I have the same problem for my app on anvil.works. I create a url and feed it but gives the same error. It error out every so often and sometimes it works.
My solution was to transition from using a SystemMessage to HumanMessage:
Old
if image:
url = f"data:image/jpeg;base64,{image}"
new_msg = SystemMessage(content=[{'type':'image_url', "image_url": {'url': url}}])
messages.append(new_msg)
logger.info("Image found in request, adding to messages.")
New
if image:
url = f"data:image/jpeg;base64,{image}"
new_msg = HumanMessage(content=[{'type':'image_url', "image_url": {'url': url}}])
messages.append(new_msg)
logger.info("Image found in request, adding to messages.")