songquanpeng / one-api

OpenAI 接口管理 & 分发系统,支持 Azure、Anthropic Claude、Google PaLM 2 & Gemini、智谱 ChatGLM、百度文心一言、讯飞星火认知、阿里通义千问、360 智脑以及腾讯混元,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用. OpenAI key management & redistribution system, using a single API for all LLMs, and features an English UI.
https://openai.justsong.cn/
MIT License
17.95k stars 4.06k forks source link

[bug] azure 服务的 gpt-4 和 gpt-4-0613 函数调用参数传递异常 #1019

Open Hk-Gosuto opened 7 months ago

Hk-Gosuto commented 7 months ago

例行检查

问题描述

使用本项目转发了 azure 服务的 openai 模型,当模型名为 gpt-4gpt-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-4gpt-4-0613 会出现该问题,与实际使用的模型版本无关。

复现步骤

在 azure 部署两个 gpt-4 模型,部署名分别为 gpt-4gpt-4-1106-preview ,模型版本随意,通过 one-api 配置转发服务并设置 api 版本为 2024-02-15-preview。 使用项目 ChatGPT-Next-Web-LangChain 分别对两个模型出发函数调用。

预期结果

正确的函数调用

相关截图

image image

Hk-Gosuto commented 6 months ago

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

songquanpeng commented 6 months ago

好的,周末处理

gouku commented 6 months ago

我也遇到了,和https://github.com/songquanpeng/one-api/issues/784 应该是一个问题

vary commented 5 months ago

我也遇到了同样的问题

gouku commented 4 months ago

好的,周末处理

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

jinjianming commented 2 months ago

我也遇到了同样的问题

Xhyxx1 commented 2 months ago

这个问题现在有解决嘛?