Skip to content

fix(ai-ollama): forward systemPrompts to Ollama API#389

Open
Spiralis wants to merge 1 commit intoTanStack:mainfrom
Spiralis:patch-1
Open

fix(ai-ollama): forward systemPrompts to Ollama API#389
Spiralis wants to merge 1 commit intoTanStack:mainfrom
Spiralis:patch-1

Conversation

@Spiralis
Copy link

@Spiralis Spiralis commented Mar 19, 2026

Fixes #388

The mapCommonOptionsToOllama() method was silently dropping the systemPrompts field from chat options. System prompts passed via chat({ systemPrompts: [...] }) now correctly reach the Ollama API as the system parameter on the chat request. This is how other adapters (e.g. Anthropic) handle it.

🎯 Changes

Forward systemPrompts as the system field on the Ollama ChatRequest in mapCommonOptionsToOllama().

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features
    • The Ollama adapter now properly supports system prompts in API requests. When system prompts are provided, they are automatically combined with line breaks and incorporated into the request payload. This enhancement enables users to provide multiple system prompts that work together for improved control over AI behavior and response quality.

The `mapCommonOptionsToOllama()` method was silently dropping the `systemPrompts` field from chat options. System prompts passed via `chat({ systemPrompts: [...] })` now correctly reach the Ollama API as the `system` parameter on the chat request. This is how other adapters (e.g. Anthropic) handle it.
Copilot AI review requested due to automatic review settings March 19, 2026 14:04
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 099f3f91-8c4b-4ba9-baa4-15dc291e56d8

📥 Commits

Reviewing files that changed from the base of the PR and between c3583e3 and 945aa51.

📒 Files selected for processing (1)
  • packages/typescript/ai-ollama/src/adapters/text.ts

📝 Walkthrough

Walkthrough

The Ollama adapter's mapCommonOptionsToOllama function now conditionally includes a system field in the ChatRequest object when options.systemPrompts is provided and non-empty, joining all prompts with newlines before forwarding to the Ollama API.

Changes

Cohort / File(s) Summary
Ollama System Prompt Mapping
packages/typescript/ai-ollama/src/adapters/text.ts
Added conditional injection of Ollama system field from options.systemPrompts by joining non-empty prompt array with \n.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A system prompt was lost in the tall grass,
The Ollama adapter let it pass!
But now with a fix, swift and keen,
The pirate speaks as it should be seen! 🏴‍☠️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: forwarding systemPrompts to the Ollama API in the ai-ollama adapter.
Description check ✅ Passed The description follows the template structure with Changes section, completed Checklist items, and Release Impact section, providing clear context linking to issue #388.
Linked Issues check ✅ Passed The PR correctly implements the fix specified in #388: adding conditional system field mapping when systemPrompts exist, matching the one-line solution proposed.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the systemPrompts forwarding issue in mapCommonOptionsToOllama; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.

OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the @tanstack/ai-ollama adapter so systemPrompts provided via core chat options are forwarded to Ollama’s Chat API as the system field, matching behavior of other adapters and resolving #388.

Changes:

  • Forward options.systemPrompts to Ollama ChatRequest.system (joined with \n) in mapCommonOptionsToOllama().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

@tanstack/ai-ollama adapter silently drops systemPrompts field

2 participants