vLLM 启动 Qwen 模型遇到 400:”auto” tool choice requires –enable-auto-tool-choice 排错记录

14次阅读
没有评论

现象

启动命令:

vllm serve mlx-community/Qwen3.8-27B-bf16 \
--language-model-only \
--trust-remote-code \
--port 8090

调用接口时报错:

Error: Error code: 400 - {'error': {'message': '"auto" tool choice requires --enable-auto-tool-choice and --tool-call-parser to be set', 'type': 'BadRequestError', 'param': None, 'code': 400}}

根因

客户端在 OpenAI 兼容请求里传入了 tools 参数,并且设置了 tool_choice="auto"。 vLLM 默认不开启自动工具选择,必须显式开启自动工具选项 + 指定工具解析器,否则直接返回 400 BadRequest。

常见触发场景:LangChain、各类 Agent SDK、AI 框架默认自动带上 tool_choice="auto",很多人没留意这个隐藏参数。

两种修复方案

方案 1:不需要工具调用(推荐,不改服务)

在调用侧修改请求:

  • 不传递 tools 数组
  • 或者显式设置 tool_choice="none"

适合普通对话场景,不需要函数调用、工具调用,最简单,不需要重启 vLLM。

方案 2:需要启用工具调用,修改启动命令

Qwen 系列模型搭配 hermes 工具解析器:

vllm serve mlx-community/Qwen3.8-27B-bf16 \
--language-model-only \
--trust-remote-code \
--enable-auto-tool-choice \
--tool-call-parser hermes \
--port 8090

重要前置坑提醒(Mac 用户重点看)

mlx-community/Qwen3.8-27B-bf16 是 MLX 格式权重,vLLM(含 vLLM Metal)不能直接加载 MLX 权重包。 上面这条命令只能解决这个 400 工具报错,后续大概率会触发权重加载失败。

两条路线区分清楚:

  1. Apple Silicon 跑 MLX 模型:使用 mlx-lm,不要用 vLLM
  2. vLLM Metal 跑模型:使用标准 HuggingFace safetensors 权重,不要直接拉 mlx-community 仓库

小结

  1. 400 报错源头:客户端 tool_choice="auto" + vLLM 未开启自动工具
  2. 无工具需求:改客户端,去掉 tools /tool_choice
  3. Agent 工具调用需求:启动参数增加 --enable-auto-tool-choice --tool-call-parser hermes
  4. 避坑:mlx-community 权重 ≠ vLLM 可用权重,二者生态不互通
正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)
验证码