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

Parallel function calling多个tool返回,token计算有误 #8

Open
q27810365 opened this issue Feb 2, 2024 · 2 comments
Open

Parallel function calling多个tool返回,token计算有误 #8

q27810365 opened this issue Feb 2, 2024 · 2 comments

Comments

@q27810365
Copy link

使用Parallel function calling,会返回多个role为tool的message。
调用模型为gpt-4-1106-preview

第一次tool calling 先不讨论,因为一般人不会用流式调用第一次tool calls,

第二次tool calls调用prompt比官方多了1。
例子:

{
    "messages": [
        {
            "role": "system",
            "content": "你是一个数学达人"
        },
        {
            "role": "user",
            "content": "两道计算题 20+70; 30x100"
        },
        {
            "role": "assistant",
            "content": null,
            "tool_calls": [
                {
                    "id": "call_ouziXPZBrGmtdxh5BnBooKI3",
                    "type": "function",
                    "function": {
                        "name": "plus",
                        "arguments": "{\"numbers\": [20, 70]}"
                    }
                },
                {
                    "id": "call_jxP70EbkqL5L78EMVK76jFDh",
                    "type": "function",
                    "function": {
                        "name": "product",
                        "arguments": "{\"numbers\": [30, 100]}"
                    }
                }
            ]
        },
        {
            "tool_call_id": "call_ouziXPZBrGmtdxh5BnBooKI3",
            "role": "tool",
            "name": "plus",
            "content": "{\"numbers\": [20, 70], \"result\": \"90\"}"
        },
        {
            "tool_call_id": "call_jxP70EbkqL5L78EMVK76jFDh",
            "role": "tool",
            "name": "product",
            "content": "{\"numbers\": [30, 100], \"result\": \"30000\"}"
        }
    ]
}

OpenAI返回

"usage": {
    "prompt_tokens": 121,
    "completion_tokens": 29,
    "total_tokens": 150
  }

本库返回
prompt_tokens 122

forestwanglin added a commit that referenced this issue Feb 3, 2024
forestwanglin added a commit that referenced this issue Feb 3, 2024
@forestwanglin
Copy link
Owner

forestwanglin commented Feb 3, 2024

When tool message's size equal 1, it use String to calculate even if the String is a JSON format. When the size is large than 1 and tool message's content is a valid JSON, it will be calculated just like arguments.

@q27810365
Copy link
Author

这个用例还是差了一些和官方返回差了点
本库prompt返回200, 官方usage返回197

{
    "model": "gpt-4-1106-preview",
    "messages": [
        {
            "role": "system",
            "content": "Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous."
        },
        {
            "role": "user",
            "content": "what is the weather going to be like in San Francisco and Glasgow over the next 4 days"
        },
        {
            "role": "assistant",
            "content": null,
            "tool_calls": [
                {
                    "id": "call_fgcP33C9qI4003cva1nXA362",
                    "type": "function",
                    "function": {
                        "name": "get_n_day_weather_forecast",
                        "arguments": "{\"location\": \"San Francisco, CA\", \"format\": \"fahrenheit\", \"num_days\": 4}"
                    }
                },
                {
                    "id": "call_wyNLB4rCWivuMVBKPrMF2Pk1",
                    "type": "function",
                    "function": {
                        "name": "get_n_day_weather_forecast",
                        "arguments": "{\"location\": \"Glasgow\", \"format\": \"celsius\", \"num_days\": 4}"
                    }
                }
            ]
        },
        {
            "tool_call_id": "call_fgcP33C9qI4003cva1nXA362",
            "role": "tool",
            "name": "get_n_day_weather_forecast",
            "content": "{\"location\": \"San Francisco, CA\", \"format\": \"celsius\", \"num_days\": 4, \"temperature\": \"24\"}"
        },
        {
            "tool_call_id": "call_wyNLB4rCWivuMVBKPrMF2Pk1",
            "role": "tool",
            "name": "get_n_day_weather_forecast",
            "content": "{\"location\": \"Glasgow\", \"format\": \"celsius\", \"num_days\": 4, \"temperature\": \"21\"}"
        }
    ]
}

@forestwanglin forestwanglin reopened this Feb 3, 2024
forestwanglin added a commit that referenced this issue Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants