fix: extract and map text-embedded tool calls with special tokens (#679)#693
Open
ansariujale wants to merge 1 commit into
Open
fix: extract and map text-embedded tool calls with special tokens (#679)#693ansariujale wants to merge 1 commit into
ansariujale wants to merge 1 commit into
Conversation
…lama#679) - Add a Pydantic �efore model validator to the Message class schema to intercept raw server response payloads before object instantiation. - Implement robust regular expression string matching to isolate embedded JSON arrays appended with the <|call|> marker token in the message text. - Extract tool metadata keys ('task', 'result_name') along with target parameters, reconstruct them into proper Message.ToolCall dictionaries, and append them natively to the ool_calls sequence array. - Cleanse the user-visible content field by removing backend technical signatures to prevent parameter leakages into the application text UI interface. - Implement isolated unit tests validating schema mutations and edge-case behaviors.
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.
Description
This PR resolves #679 where specific cloud/merged models output structured tool-calling JSON blocks and special tokens (
<|call|>) directly into the text content stream instead of utilizing standard API arrays.Changes
@model_validator(mode='before')inside theMessageclass (src/ollama/_types.py).<|call|>sequence.task/result_name) and executionparams, automatically appending them as validMessage.ToolCallschemas.contentstring to prevent backend function arguments from leaking into application text interfaces.Testing
tests/test_model_parsing.py) simulating the exact payload from the issue.pytest.