Skip to content

Route think and keep_alive to the top level of Ollama chat requests - #200

Merged
mattt merged 1 commit into
huggingface:mainfrom
james-333i:fix/152-ollama-think
Sep 10, 2026
Merged

mattt merged 1 commit into
huggingface:mainfrom
james-333i:fix/152-ollama-think

Conversation

@james-333i

Copy link
Copy Markdown
Contributor

Ollama's /api/chat endpoint reads think and keep_alive as top-level siblings of model and messages, so passing them through the custom options dictionary buried them inside options where the server ignores them.

Route those keys to the top level of the request body and keep every other custom key in options. Reserved request keys cannot be overridden. Adds request-encoding tests that run without a live Ollama server.

Fixes #152

Resubmitted after an accidental force push closed #184.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The newly supported keep_alive routing lacks request-encoding coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Routes Ollama’s think and keep_alive options to /api/chat’s top-level request body while retaining other custom options under options.

Changes:

  • Extracts recognized top-level parameters.
  • Applies routing to streaming and non-streaming requests.
  • Adds request-construction tests.
File summaries
File Description
Sources/AnyLanguageModel/Models/OllamaLanguageModel.swift Implements top-level parameter routing.
Tests/AnyLanguageModelTests/OllamaLanguageModelTests.swift Tests routing and reserved-key protection.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Sources/AnyLanguageModel/Models/OllamaLanguageModel.swift
Ollama's /api/chat endpoint reads think and keep_alive as top-level
siblings of model and messages, so passing them through the custom
options dictionary buried them inside options where the server
ignores them.

Route those keys to the top level of the request body and keep every
other custom key in options. Reserved request keys cannot be
overridden. Adds request-encoding tests that run without a live
Ollama server.

Fixes huggingface#152
@james-333i

Copy link
Copy Markdown
Contributor Author

@mattt Rebased onto main and added a keep_alive encoding test alongside the think one.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation correctly covers synchronous and streaming requests with focused regression tests.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@mattt
mattt merged commit 13e22f2 into huggingface:main Sep 10, 2026
11 checks passed
@mattt

mattt commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks, @james-333i!

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.

Support top-level request parameters for OllamaLanguageModel (e.g. think)

3 participants