Azure OpenAI GPT-4o含图片时函数调用返回400错误求助
Azure OpenAI GPT-4o 函数调用返回400错误
测试Azure OpenAI最新的GPT-4o模型时,尽管输入的messages格式正确,但调用函数时仍返回400错误。
触发特征:
- 仅在第一个问题中包含图片时才会触发该错误
- 使用OpenAI官方服务而非AzureOpenAI时,代码运行完全正常
- 移除第一条消息中的图片后,代码也能正常运行
怀疑是AzureOpenAI客户端的问题,想咨询是否有人遇到过类似情况。
测试代码
from openai import OpenAI, AzureOpenAI # client = OpenAI() client = AzureOpenAI( azure_endpoint='https://xxx.openai.azure.com/', api_version="2024-02-01", api_key='xxx' ) msg=[ { "role": "user", "content": [ {"type": "text", "text": "What is in the image?"}, { "type": "image_url", "image_url": { "url": "https://images.freeimages.com/images/large-previews/c04/puppy-1367856.jpg" } } ] }, {"role": "assistant", "content": "There is a small dog in the image"}, {"role": "user", "content": [{"type": "text", "text": "What is today?"}]}, {"role": "assistant", "content": "", "tool_calls": [{"id": "call_rkBDeJsY9mCnzFchblUV2ZHt", "function": {"arguments": "{}", "name": "get_current_date"}, "type": "function"}]}, {"tool_call_id": "call_rkBDeJsY9mCnzFchblUV2ZHt", "role": "tool", "name": "get_current_date", "content": "2024-05-21 19:52:24.775703"} ] completion = client.chat.completions.create( model='gpt-4o', messages=msg, temperature=0 ) choice = completion.choices[0].message print(choice)
返回错误信息
openai.BadRequestError: Error code: 400 - {'error': {'message': "An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_rkBDeJsY9mCnzFchblUV2ZHt", 'type': 'invalid_request_error', 'param': 'messages', 'code': None}}
内容的提问来源于stack exchange,提问作者Hung Nguyen
相关产品推荐
相关产品推荐

