Fix/gemini cloud tool calling#15
Merged
Merged
Conversation
ollama-rs 0.3.4 serializes ToolType::Function as "Function" (uppercase F), but Ollama Cloud / Gemini strictly requires lowercase "function" per the API spec. This caused HTTP 400 errors: "Invalid tool type". Also add the missing "name" field to "role: tool" messages, which Gemini requires to match tool results back to tool calls. Both fixes are applied as JSON post-processing in stream_ollama_chat() just before sending the HTTP request, avoiding changes to data structures.
Three fixes for Ollama Cloud / Gemini compatibility: 1. Tool type casing: ollama-rs 0.3.4 serializes ToolType::Function as "Function" (uppercase F), but Gemini requires lowercase "function". Post-process request JSON to normalize it. Fixes "Invalid tool type". 2. Missing 'name' on tool messages: Gemini requires the 'name' field on 'role: tool' messages to match results to calls. Inject it from the preceding assistant message's tool_calls. 3. Missing thought_signature: Gemini requires a thought_signature on function call parts in multi-turn tool calling. ollama-rs drops this field. Capture it from raw SSE response JSON (via OllamaChunk) and store it in ToolCallFunction.thought_signature. Re-inject it in follow-up requests via fix_request_json. Added ToolCallFunction.thought_signature: Option<String> to the shared provider types (with serde(skip_serializing_if = Option::is_none)).
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.
This PR fixes tool calling with ollama cloud gemini 3 flash preview model