Skip to content

fix: extract and map text-embedded tool calls with special tokens (#679)#693

Open
ansariujale wants to merge 1 commit into
ollama:mainfrom
ansariujale:fix/cloud-tool-parsing-679
Open

fix: extract and map text-embedded tool calls with special tokens (#679)#693
ansariujale wants to merge 1 commit into
ollama:mainfrom
ansariujale:fix/cloud-tool-parsing-679

Conversation

@ansariujale

Copy link
Copy Markdown

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

  • Implemented a self-contained @model_validator(mode='before') inside the Message class (src/ollama/_types.py).
  • Added robust Regex and JSON parsing to intercept incoming payloads containing the <|call|> sequence.
  • Safely extracts the embedded tool names (task/result_name) and execution params, automatically appending them as valid Message.ToolCall schemas.
  • Cleanses the public content string to prevent backend function arguments from leaking into application text interfaces.

Testing

  • Created a dedicated unit test suite (tests/test_model_parsing.py) simulating the exact payload from the issue.
  • Verified that content truncation, tool reconstruction, and parameter mappings pass flawlessly under pytest.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gpt-oss:20b-cloud damaged output after last update

1 participant