genkit icon indicating copy to clipboard operation
genkit copied to clipboard

[JS] Ollama generate inserts commas between prompt and system text parts

Open FOWEPJF255 opened this issue 3 weeks ago • 0 comments

Describe the bug

The JS Ollama plugin inserts commas between the text parts of a message when using type: 'generate'. Both the user prompt and system instruction are affected, so the plugin changes caller-provided instructions before sending them to the model.

getPrompt and getSystemMessage in js/plugins/ollama/src/index.ts call m.content.map((c) => c.text).join() with the default comma separator. Genkit's Message.text joins text parts without a separator, and the same plugin's chat path concatenates parts without adding punctuation.

To Reproduce

Checked on Genkit main 68eb8cc80c14aa33a60bd977bf7600b8ed878d35 (genkit / genkitx-ollama 1.44.0). This uses the real plugin with a captured request; no Ollama server or model is required:

import { genkit } from 'genkit';
import { ollama } from 'genkitx-ollama';

globalThis.fetch = async (_url, init) => {
  const body = JSON.parse(init!.body as string);
  console.log(JSON.stringify({ prompt: body.prompt, system: body.system }));
  return new Response(JSON.stringify({ response: 'done', done: true }));
};

const ai = genkit({
  plugins: [ollama({
    serverAddress: 'http://stub',
    models: [{ name: 'local-model', type: 'generate' }],
  })],
});
await ai.generate({
  model: 'ollama/local-model',
  system: [{ text: 'Speak only ' }, { text: 'JSON.' }],
  prompt: [{ text: 'Return the exact token ' }, { text: 'abcdef' }],
});

Observed outgoing payload fields:

{
  "prompt": "Return the exact token ,abcdef",
  "system": "Speak only ,JSON."
}

An empty text part also introduces an unwanted comma. Literal commas supplied by the caller should of course remain unchanged.

Expected behavior

Text parts within each message concatenate exactly as Message.text does:

{
  "prompt": "Return the exact token abcdef",
  "system": "Speak only JSON."
}

The fix can preserve the existing behavior between separate messages; the defect reported here is the added punctuation between parts of the same message.

Runtime

  • OS: Windows
  • Version: Genkit / genkitx-ollama 1.44.0, main 68eb8cc80

Node version

  • v24.18.0

Additional context

This is separate from #7119 / #7120, which fix the wire type of generation stop sequences. Searches for ollama comma, ollama prompt join and getSystemMessage did not find an existing report or fix for text-part concatenation. AI assistance was used for investigation and reproduction.

FOWEPJF255 avatar Nov 08 '26 18:11 FOWEPJF255