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
Copy Markdown

@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
Copy Markdown
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
Copy Markdown

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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 27, 2026

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/@tanstack/ai@389

@tanstack/ai-anthropic

npm i https://pkg.pr.new/@tanstack/ai-anthropic@389

@tanstack/ai-client

npm i https://pkg.pr.new/@tanstack/ai-client@389

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/@tanstack/ai-devtools-core@389

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@389

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@389

@tanstack/ai-fal

npm i https://pkg.pr.new/@tanstack/ai-fal@389

@tanstack/ai-gemini

npm i https://pkg.pr.new/@tanstack/ai-gemini@389

@tanstack/ai-grok

npm i https://pkg.pr.new/@tanstack/ai-grok@389

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@389

@tanstack/ai-ollama

npm i https://pkg.pr.new/@tanstack/ai-ollama@389

@tanstack/ai-openai

npm i https://pkg.pr.new/@tanstack/ai-openai@389

@tanstack/ai-openrouter

npm i https://pkg.pr.new/@tanstack/ai-openrouter@389

@tanstack/ai-preact

npm i https://pkg.pr.new/@tanstack/ai-preact@389

@tanstack/ai-react

npm i https://pkg.pr.new/@tanstack/ai-react@389

@tanstack/ai-react-ui

npm i https://pkg.pr.new/@tanstack/ai-react-ui@389

@tanstack/ai-solid

npm i https://pkg.pr.new/@tanstack/ai-solid@389

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/@tanstack/ai-solid-ui@389

@tanstack/ai-svelte

npm i https://pkg.pr.new/@tanstack/ai-svelte@389

@tanstack/ai-vue

npm i https://pkg.pr.new/@tanstack/ai-vue@389

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/@tanstack/ai-vue-ui@389

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@389

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/@tanstack/react-ai-devtools@389

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@389

commit: 945aa51

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 27, 2026

View your CI Pipeline Execution ↗ for commit 945aa51

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 20s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 42s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-27 18:47:01 UTC

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