minicpm5-2b native tool calls never parse

这个报错通常出现在把 MiniCPM5-2B 的 GGUF 模型导入 Ollama 并传入 tools 后,模型返回的 tool_calls 始终为 null ,而 content 里只剩残缺的 XML 片段,典型表现为 minicpm5-2b native tool calls never par

快速结论:这个报错通常出现在把 MiniCPM5-2B 的 GGUF 模型导入 Ollama 并传入 tools 后,模型返回的 tool_calls 始终为 null,而 content 里只剩残缺的 XML 片段,典型表现为 minicpm5-2b native tool calls never parse。优先排查自建 Modelfile 是否把 MiniCPM5 的 XML 工具调用标签(special tokens)剥掉了。

适用环境:Ollama 0.30.8,Windows + Intel CPU + Nvidia GPU;模型通过 ollama run hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M 拉取使用(Ollama 官方尚未正式支持该模型)。

最快修复方案:重新正确配置模型的 Modelfile 后再导入。Issue 中报告者确认:之前是 Modelfile 配置错误,改正后工具调用即正常。

注意事项:Issue 原帖使用的 minicpm5-2b:latest 无法直接 ollama pull(会报 file does not exist)。复现者改用 ollama cp hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M minicpm5-2b:18483 后,100 次工具调用全部成功,因此原帖的失败并非 Ollama 解析器本身的问题。若你的 Modelfile 仍为原始错误配置,本方案不一定直接适用。

问题场景

用户在 Ollama 中运行 MiniCPM5-2B(GGUF 导入版),通过 /api/chat/v1/chat/completions 传入 tools 请求原生工具调用。模型的 reasoning/thinking 字段能正确表达“要调用 get_weather”,但接口返回的 tool_callsnull(OpenAI 兼容接口下直接缺失),content 只剩下被打散的 XML 片段,finish_reason/done_reason 始终是 stop。依赖 tool_callsfinish_reason: tool_calls 分支的客户端因此永远不会进入工具调用逻辑。

报错原文

minicpm5-2b native tool calls never parse

{"model":"minicpm5-2b:latest",
 "message":{"role":"assistant",
  "content":" name=\"get_weather\"> name=\"city\">Paris",
  "thinking":"The user wants to know the weather in Paris. I need to use the get_weather function.\n"},
 "done":true,"done_reason":"stop"}

原因分析

Issue 中给出的可能原因指向模型导入时的 Modelfile 配置:MiniCPM5 的工具调用依赖 XML 标签,而这些标签是 special tokens,解析工具调用前不应被剥离(上游 vLLM 的 minicpm5xml_tool_parser.py 明确要求 request.skip_special_tokens = False,SGLang 也提供 --tool-call-parser minicpm5)。如果 Modelfile 把 special tokens 当作普通特殊符号过滤掉,模型输出的 XML 结构就会被破坏成 name="get_weather"> name="city">Paris 这种残片,导致 Ollama 无法从中解析出结构化 tool_calls。报告者最终确认问题出在自己错误配置的 Modelfile,改正后模型工作正常,说明这不是 Ollama 解析器缺陷。

环境排查

  • 确认 Ollama 版本:原帖为 0.30.8。
  • 确认模型来源:是否使用 hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M,并检查导入时使用的 Modelfile 内容。
  • 确认所使用的具体模型 tag(原帖的 minicpm5-2b:latest 并非可直接 pull 的官方模型)。
  • 确认操作系统(Windows)、CPU(Intel)、GPU(Nvidia)等运行环境。
  • 确认 /api/chat/v1/chat/completions 两种调用路径下的返回差异。
  • 必要时查看 Ollama 服务日志以定位解析阶段的行为。

解决步骤

  1. 先排除模型不存在的问题:如果执行 ollama pull minicpm5-2b:latest 返回 pull model manifest: file does not exist,说明该 tag 不存在,需先用已有模型复制出可测试的 tag,例如 ollama cp hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M minicpm5-2b:18483
  2. 检查自建 Modelfile 中是否包含会剥离 special tokens 或改变模板/停止符的处理。可对照上游 MiniCPM5 工具调用要求,确保 XML 工具调用标签不会被当作普通文本过滤。
  3. 修正 Modelfile 后重新创建并加载模型,然后用与原帖相同的 curl 请求向 /api/chat 传入 tools 进行测试。
  4. 如果需要,再重复调用多次以确认结果稳定,Issue 中复现者连续 100 次均返回一致的 tool_calls
  5. 确认无误后再接入依赖 tool_calls/finish_reason: tool_calls 分支的客户端。

验证方法

/api/chat 发送带 tools 的请求,检查返回中 message.tool_calls 不再为 null,而是包含类似 {"function":{"name":"get_weather","arguments":{"city":"Paris"}}} 的结构;同时 content 中不再出现 name="get_weather"> name="city">Paris 这类残片。若连续多次请求返回结果一致(例如复现者的 100 次调用 md5 全部相同),可确认问题已解决。原帖报告者也通过改正 Modelfile 后确认工具调用恢复正常。

参考来源

ollama/ollama #18483

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 24441

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注