网站制作学习网AI→正文:GPT-4o The model produced invalid content. Consider modifying your pro
字体:

GPT-4o The model produced invalid content. Consider modifying your pro

AI 2024/6/13 19:07:30  点击:不统计

原载于:转www.载for网站制作学习asp必.cn究
 在使用GPT-4o版本调用function_call 时,出现了错误,错误代码如下:

 
openai.error.APIError: The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently. {
  "error": {
    "message": "The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently.",
    "type": "model_error",
    "param": null,
    "code": null
  }
}
多次失败重试,调用function_call ,实际返回内容 
 
{
  "id": "chatcmpl-9ZYpac9udCvke5wRQG6oi2g4GpbwR",
  "object": "chat.completion",
  "created": 1718262398,
  "model": "GPT-4o-2024-05-13",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "function_call": {
          "name": "functions", # 这里是错误的,没有返回对应的function_call 的function name, 但参数是正确的
          "arguments": "{\n  \"mysql_code_str\": \"select name from table"\n}"
        }
      },
      "logprobs": null,
      "finish_reason": "function_call"
    }
  ],
  "usage": {
    "prompt_tokens": 662,
    "completion_tokens": 42,
    "total_tokens": 704
  },
  "system_fingerprint": "fp_319be4768e"
}
 
在实际调用时 出现了 functions 不存在的问题。 虽然参数正确。但无济于事。
 
1. 检查问题:
(1)那为什么出现了,后来查询 官方模型 说明
官方模型:https://platform.openai.com/docs/models
 
看到GPT-4o 和 gpt-4-turbo(或者以前的模型)有个区别:
就是 gpt-4-turbo(或者以前的模型) :Vision requests can now use JSON mode and function calling 这句,GPT-4o 模型是不支持 function_call 的。
 
那替代 function calling 的是那个?是 tools
官方文档:https://platform.openai.com/docs/guides/function-calling
 
在新版本已经没有了function_call 的参数
(2)检查本地 openai 的python 的扩展版本,升级为最新版本
 
解决问题:
更新pip openai 版本
调整调用函数为 tools 
官方案例:https://platform.openai.com/docs/assistants/tools/function-calling/quickstart

原载于:网f站o学a习s制p作.cn

·上一篇:llama3 运行需要多少内存 >>    ·下一篇:GPT-4o 不再支持function_call 更改为tools >>
推荐文章
最新文章