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
18.21k stars 4.11k forks source link

通义千问流式输出的情况下function call异常 #1403

Open hejuntt1014 opened 5 months ago

hejuntt1014 commented 5 months ago

例行检查

问题描述 通义千问流式输出的情况下function call异常,阿里官方文档显示incremental_output和stream是不支持同时设置的,但是源码中IncrementalOutput直接用request.Stream赋值了,这会使得Stream下function call输出异常 image

复现步骤

curl http://127.0.0.1:3000/v1/chat/completions \
-H "Authorization: Bearer sk-" \
-H "Content-Type: application/json" \
-d '{
  "model": "qwen1.5-72b-chat",
  "stream": true, 
  "messages": [
    {
      "role": "user",
      "content": "茂名天气怎样"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_current_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g. San Francisco, CA"
            },
            "unit": {
              "type": "string",
              "enum": ["celsius", "fahrenheit"]
            }
          },
          "required": ["location"]
        }
      }
    }
  ],
  "tool_choice": "auto"
}'

预期结果 希望在Stream流式输出的情况下获得openai官方api一致的输出结果

相关截图 异常数据: image

hejuntt1014 commented 5 months ago

另外,tool_calls也没有组装进message的消息体里面 image

johnlanni commented 3 months ago

可以试试 higress : https://github.com/alibaba/higress/issues/1023