Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qwen2的function calling数据格式不对 #4792

Closed
1 task done
missley opened this issue Jul 12, 2024 · 7 comments
Closed
1 task done

qwen2的function calling数据格式不对 #4792

missley opened this issue Jul 12, 2024 · 7 comments
Labels
solved This problem has been already solved

Comments

@missley
Copy link

missley commented Jul 12, 2024

Reminder

  • I have read the README and searched the existing issues.

System Info

  • llamafactory version: 0.8.3.dev0
  • Platform: Linux-4.19.36-vhulk1907.1.0.h1524.eulerosv2r8.aarch64-aarch64-with-glibc2.28
  • Python version: 3.10.14
  • PyTorch version: 2.1.0 (NPU)
  • Transformers version: 4.41.2
  • Datasets version: 2.18.0
  • Accelerate version: 0.30.1
  • PEFT version: 0.11.1
  • TRL version: 0.9.4
  • NPU type: Ascend910ProB
  • CANN version: 8.0.RC1

Reproduction

curl --location --request POST 'http://xxx/qwen2/v1/chat/completions' \
--header 'Content-Type: application/json' \
--data-raw '{
    "messages": [
        {
            "content": "我的工号是xxxx",
            "role": "system"
        },
        {
            "content": "我的交付组长的考勤是否有迟到?",
            "role": "user"
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "获取员工的交付组长信息",
                "description": "获取员工的交付组长信息",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "工号": {
                            "type": "string",
                            "description": "员工工号"
                        }
                    },
                    "required": [
                        "工号"
                    ]
                }
            }
        },
        {
            "type": "function",
            "function": {
                "name": "查询考勤信息",
                "description": "查询考勤信息",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "工号": {
                            "type": "string",
                            "description": "员工工号"
                        }
                    },
                    "required": [
                        "工号"
                    ]
                }
            }
        }
    ],
    "model": "qwen2",
    "stream": false,
    "max_tokens": 2024,
    "temperature": 0.2,
    "top_p": 0.3
}'

response:

{
    "id": "chatcmpl-04688b25903e4bff9356ffd4da2b3343",
    "object": "chat.completion",
    "created": 1720766740,
    "model": "qwen2",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Action: 查询考勤信息.\nAction Input: {\"工号\": \"xxxxxx\"}",
                "tool_calls": null
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 189,
        "completion_tokens": 23,
        "total_tokens": 212
    }
}

Expected behavior

正常格式应该如glm4:

{
    "id": "chatcmpl-b52a8a637df84b7cb43285af6f241b1c",
    "object": "chat.completion",
    "created": 1720766757,
    "model": "EMPTY",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": null,
                "tool_calls": [
                    {
                        "id": "call_b80cde8bbf8545cf903e01136ce5d9b0",
                        "type": "function",
                        "function": {
                            "name": "获取员工的交付组长信息",
                            "arguments": "{\"工号\": \"xxxxx\"}"
                        }
                    }
                ]
            },
            "finish_reason": "tool_calls"
        }
    ],
    "usage": {
        "prompt_tokens": 275,
        "completion_tokens": 16,
        "total_tokens": 291
    }
}

Others

No response

@xiaojun777-huang
Copy link

tool_utils.py文件中,Action: tool name (one of [{tool_names}]). 这段提示会有概率返回extract_tools无法解析的文本。你给定的文本中就出现了一个小数点.正则匹配出错了。建议将提示词修改为Action: one of [{tool_names}]。不过这段tools的逻辑还是问题蛮多的,我提交了一个issue,你可以参考一下。

@lwj2001
Copy link

lwj2001 commented Jul 12, 2024

tool_utils.py文件中,Action: tool name (one of [{tool_names}]). 这段提示会有概率返回extract_tools无法解析的文本。你给定的文本中就出现了一个小数点.正则匹配出错了。建议将提示词修改为Action: one of [{tool_names}]。不过这段tools的逻辑还是问题蛮多的,我提交了一个issue,你可以参考一下。

您好,这个 tool_utils.py 文件在哪呢,我想根据我的训练数据来修改正则匹配

@xiaojun777-huang
Copy link

llama factory源码

@lwj2001
Copy link

lwj2001 commented Jul 12, 2024

llama factory源码

了解!原来是我的版本太低了,hh

@codemayq codemayq added the solved This problem has been already solved label Jul 13, 2024
hiyouga added a commit that referenced this issue Jul 13, 2024
@hiyouga
Copy link
Owner

hiyouga commented Jul 13, 2024

fixed

@xiaojun777-huang
Copy link

建议将tool name也去掉,我做的测试用例,Qwen2-7b-Instruct还是有挺高概率返回Action: tool name (plus_func) Action Input: {A:1,B:2},这样的字符串。这个字符串extract_tools里的正则表达式无法正确处理。

xtchen96 pushed a commit to xtchen96/LLaMA-Factory that referenced this issue Jul 17, 2024
@Imbernoulli
Copy link

请问在这个问题中哪里用到了这个repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved This problem has been already solved
Projects
None yet
Development

No branches or pull requests

6 participants