Skip to content

vllm 部署 DeepSeek V3 启用 Function Call 的正确参数

问题

使用 vllm 在本地部署 DeepSeek V3 / V3-0324 时,按照网上教程添加 --tool-call-parser hermes 后仍然报 500 错误,或出现 finish_reason = "tool_calls"tool_calls = [] 为空的问题。

根因

DeepSeek V3 使用的 tool call token 格式是专有的(如 <|tool▁calls▁begin|>),不兼容 hermes 解析器。需要使用 vllm 专门为 DeepSeek V3 提供的 deepseek_v3 解析器。

解决方案

启动 vllm 服务时使用正确的 --tool-call-parser 参数:

bash
# 错误(会 500 或 tool_calls 为空)
vllm serve deepseek-ai/DeepSeek-V3-0324 \
  --enable-auto-tool-choice \
  --tool-call-parser hermes

# 正确
vllm serve deepseek-ai/DeepSeek-V3-0324 \
  --enable-auto-tool-choice \
  --tool-call-parser deepseek_v3

完整启动示例

bash
vllm serve deepseek-ai/DeepSeek-V3-0324 \
  --tensor-parallel-size 8 \
  --max-model-len 32768 \
  --enable-auto-tool-choice \
  --tool-call-parser deepseek_v3 \
  --trust-remote-code

验证是否正常

python
import openai
client = openai.OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[{"role": "user", "content": "查询北京天气"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "获取天气",
            "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}
        }
    }]
)
print(response.choices[0].finish_reason)  # 应为 "tool_calls"
print(response.choices[0].message.tool_calls)  # 应有内容

来源Issue #944 - deepseek-ai/DeepSeek-V3