one-api [bug] Azure 服务的 gpt-4 和 gpt-4-0613 函数调用参数传递异常

8ftvxx2r  于 2个月前  发布在  其他
关注(0)|答案(7)|浏览(53)
例行检查

* 我已确认目前没有类似 issue
* 我已确认我已升级到最新版本
* 我已完整查看过项目 README,尤其是常见问题部分
* 我理解并愿意跟进此 issue,协助测试和提供反馈
* 我理解并认可上述内容,并理解项目维护者精力有限,**不遵循规则的 issue 可能会被无视或直接关闭**

问题描述
使用本项目转发了 azure 服务的 openai 模型,当模型名为 `gpt-4` 和 `gpt-4-0613` 时,基于 `tool_call` 模式的函数调用会出现以下错误:

{
"error": true,
"message": "400 Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'. (request id: 2024021906343052982873tJOHHMck)"
}


当模型名为 `gpt-4-1106-preview` 时则函数调用正常。
 API 版本为: `2024-02-15-preview` 
 目前看来只有当部署名为 `gpt-4` 和 `gpt-4-0613` 会出现该问题,与实际使用的模型版本无关。

复现步骤
在 azure 部署两个 gpt-4 模型,部署名分别为 `gpt-4` 和 `gpt-4-1106-preview` ,模型版本随意,通过 one-api 配置转发服务并设置 api 版本为 `2024-02-15-preview` 。
使用项目 [ChatGPT-Next-Web-LangChain](https://github.com/Hk-Gosuto/ChatGPT-Next-Web-LangChain) 分别对两个模型出发函数调用。

预期结果
正确的函数调用

相关截图

![](//img.saoniuhuo.com/images/202407/8121721845833885.jpg)

![](//img.saoniuhuo.com/images/202407/31371721845835249.jpg)
von4xj4u

von4xj4u1#

playload

{
    "model": "gpt-4",
    "temperature": 0.5,
    "top_p": 1,
    "frequency_penalty": 0,
    "presence_penalty": 0,
    "n": 1,
    "stream": false,
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "google_search",
                "description": "a search engine. useful for when you need to answer questions about current events. input should be a search query.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "input": {
                            "type": "string"
                        }
                    },
                    "additionalProperties": false,
                    "$schema": "http://json-schema.org/draft-07/schema#"
                }
            }
        },
        {
            "type": "function",
            "function": {
                "name": "calculator",
                "description": "Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "input": {
                            "type": "string"
                        }
                    },
                    "additionalProperties": false,
                    "$schema": "http://json-schema.org/draft-07/schema#"
                }
            }
        },
        {
            "type": "function",
            "function": {
                "name": "web-browser",
                "description": "useful for when you need to find something on or summarize a webpage. input should be a comma separated list of \"ONE valid http URL including protocol\",\"what you want to find on the page or empty string for a summary\".",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "input": {
                            "type": "string"
                        }
                    },
                    "additionalProperties": false,
                    "$schema": "http://json-schema.org/draft-07/schema#"
                }
            }
        }
    ],
    "messages": [
        {
            "role": "system",
            "content": "\nYou are ChatGPT, a large language model trained by OpenAI.\nKnowledge cutoff: 2021-09\nCurrent model: gpt-4\nCurrent time: 2024/2/22 21:18:27\nLatex inline: $x^2$ \nLatex block: $$e=mc^2$$\n\n"
        },
        {
            "role": "user",
            "content": "搜索一下上海明天的天气"
        },
        {
            "role": "assistant",
            "content": "",
            "tool_calls": [
                {
                    "index": 0,
                    "id": "call_iBvwBjtYGFvw37FmwtQ5UTKO",
                    "type": "function",
          "function": {
            "name": "google_search",
            "arguments": "{\n  \"input\": \"上海明天的天气\"\n}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "content": "{\"type\":\"weather_result\",\"temperature\":\"41\",\"unit\":\"Fahrenheit\",\"precipitation\":\"10%\",\"humidity\":\"81%\",\"wind\":\"13 mph\",\"location\":\"上海\",\"date\":\"Friday\",\"weather\":\"Cloudy\"}",
      "tool_call_id": "call_iBvwBjtYGFvw37FmwtQ5UTKO"
    }
  ]
}

最终发送到 azure 的请求会缺失 $.messages[3].tool_call_id

zpjtge22

zpjtge222#

好的,周末处理。

mnowg1ta

mnowg1ta3#

我也遇到了这个问题,和 #784 应该是同一个问题。

pdsfdshx

pdsfdshx4#

我也遇到了同样的问题。

qyuhtwio

qyuhtwio5#

好的,周末处理。

@songquanpeng ping一下看看有没有啥进展。另外我看到azure用的是toolCallId而不是tool_call_id。不知道是不是跟这个有关系 vercel/ai#1369

o3imoua4

o3imoua46#

我也遇到了同样的问题。

vjrehmav

vjrehmav7#

这个问题现在有解决吗?

相关问题