Fix: minicpm5-2b native tool calls never parse - #18499
Open
SIDDARTHAREDDY8 wants to merge 1 commit into
Open
SIDDARTHAREDDY8 wants to merge 1 commit into
SIDDARTHAREDDY8 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18483.
Fix #18483: MiniCPM5 native tool calls never parse. Root cause: MiniCPM5 emits tool calls as XML using special vocabulary tokens (//etc.), but the runner stripped those tokens during detokenization, leaving mangled fragments like
name="get_weather">that no parser could recognize. Change: (1) new MiniCPM5Parser in model/parsers that preserves all 8 XML tool-call special tokens and parses ... blocks (streaming-safe, handles thinking, wrappers, CDATA params, unknown-tool fallback to content); registered as "minicpm5" in ParserForName; (2) template-based auto-detection (MiniCPM5 identifies as generic llama, so identifiers cannot detect it) via create.IsMiniCPM5ChatTemplate, wired into safetensors inference (create/metadata.go) and GGUF create path (server/create.go). Once parsed, tool_calls flow through the existing response paths and OpenAI finish_reason is rewritten stop->tool_calls automatically.Tests pass: go test ./model/parsers/ (all pass incl. 17 new MiniCPM5 cases: native tool call incl. the issue exact get_weather/Paris scenario, streaming split-tag cases, thinking, CDATA, wrapper, multiple calls, unknown-tool fallback, preserved-tokens, registration); go test ./create/ (all pass incl. new minicpm5 safetensors-family and capabilities cases); go vet clean on both packages; gofmt clean. server/create.go edit verified in context (syntax-ok; package-level compile blocked only by sparse-checkout sibling files, no type errors in the edited file).