vllm-project / vllm

A high-throughput and memory-efficient inference and serving engine for LLMs
https://docs.vllm.ai
Apache License 2.0
30.97k stars 4.71k forks source link

[Bug]: tool_calls parsing error with CPU #7827

Open xuechendi opened 3 months ago

xuechendi commented 3 months ago

Your current environment

The output of `python collect_env.py` ```text Your output of `python collect_env.py` here ```

🐛 Describe the bug

from openai import OpenAI

if __name__ == "__main__":

    model = "mistralai/Mistral-7B-Instruct-v0.3"
    llm = OpenAI(base_url="http://100.83.111.250:8000/v1", api_key="EMPTY")

    input = [{"role": "user", "content": "What's the weather like in Boston today?"}]
    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 = {'function': {'name': 'get_current_weather'}} 

    output = llm.chat.completions.create(
        model=model,
        messages=input,
        tools=tools,
        tool_choice=tool_choice,
        stream=False,
    )
    if content := output.choices[0].message.content:
        print('content:', content)
    elif tool_calls := output.choices[0].message.tool_calls:
        print('tool_calls:', tool_calls)

received output:

python test_openai_sdk.py 
tool_calls: [ChatCompletionMessageToolCall(id='chatcmpl-tool-a081c6fb632c4d7bbfd3ed00ac5a4399', function=Function(arguments='{ ', name='get_current_weather'), type='function')]

expected output

python test_openai_sdk.py 
tool_calls: [ChatCompletionMessageToolCall(id='chatcmpl-tool-b58a97994c5d4de7bc817a36dcf5e95d', function=Function(arguments='{ "location": "Boston, MA", "unit": "celsius" }', name='get_current_weather'), type='function')]

Before submitting a new issue...

github-actions[bot] commented 6 days ago

This issue has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this issue should remain open. Thank you!