Skip to content

fix(openai): relax tool call validation for Ollama compatibility#113

Open
Gustave-241021 wants to merge 1 commit intocharmbracelet:mainfrom
Gustave-241021:fix/ollama-streaming-tool-calls
Open

fix(openai): relax tool call validation for Ollama compatibility#113
Gustave-241021 wants to merge 1 commit intocharmbracelet:mainfrom
Gustave-241021:fix/ollama-streaming-tool-calls

Conversation

@Gustave-241021
Copy link

@Gustave-241021 Gustave-241021 commented Jan 6, 2026

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

related link:

issue: charmbracelet/crush#1767
crush's fix: charmbracelet/crush#1774

Problem Attribution:

Ollama's OpenAI-compatible streaming API does not include id and type fields in tool call delta chunks, unlike the standard OpenAI format. This causes the fantasy library's strict validation to fail, resulting in Crush getting stuck in a "waiting" state.

Fix: Relaxed tool call validation in language_model.go to handle missing fields gracefully:

  • Default type to "function" when not provided
  • Generate synthetic ID tool-call-{index} when ID is missing
  • Skip empty delta chunks instead of erroring
  • Ensure consistent ID usage throughout the streaming handler

Risk Mitigation:

  • Only applies defaults when fields are missing, preserving standard OpenAI behavior
  • All 7 fantasy packages pass existing tests, confirming no regression
  • Explicit type validation still catches wrong types (e.g., type: "invalid")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants