[JS] Ollama stopSequences is serialized as a string instead of an array
Describe the bug
The JS Ollama plugin serializes config.stopSequences as a string rather than the array Ollama requires. Both /api/chat and /api/generate are affected. For example, ['<END>', '<USER>'] becomes options.stop: '<END><USER>'.
js/plugins/ollama/src/index.ts currently uses options.stop = stopSequences.join(''). Ollama's Options.Stop is []string; its Options.FromMap slice branch rejects a non-array with option "stop" must be of type array.
To Reproduce
Checked on Genkit main at 68eb8cc80c14aa33a60bd977bf7600b8ed878d35 (genkit / genkitx-ollama 1.44.0). This captures the real plugin's outgoing requests without a running model or credentials:
import { genkit } from 'genkit';
import { ollama } from 'genkitx-ollama';
const requests: { url: string; stop: unknown }[] = [];
globalThis.fetch = async (url, init) => {
const body = JSON.parse(init!.body as string);
requests.push({ url: String(url), stop: body.options.stop });
return new Response(JSON.stringify({
model: 'local-model',
message: { role: 'assistant', content: 'done' },
response: 'done',
done: true,
}));
};
for (const type of ['chat', 'generate'] as const) {
const ai = genkit({
plugins: [ollama({
serverAddress: 'http://stub',
models: [{ name: 'local-model', type }],
})],
});
await ai.generate({
model: 'ollama/local-model',
prompt: 'hello',
config: { stopSequences: ['<END>', '<USER>'] },
});
}
console.log(requests);
Observed:
[
{ "url": "http://stub/api/chat", "stop": "<END><USER>" },
{ "url": "http://stub/api/generate", "stop": "<END><USER>" }
]
This is a request-serialization reproduction; I have not run a live Ollama inference request.
Expected behavior
Both endpoints receive options.stop: ['<END>', '<USER>'], preserving each stop sequence and its order. A single stop sequence and an empty array should also retain their array shape; an omitted setting should stay omitted.
Runtime
- OS: Windows
- Version: Genkit / genkitx-ollama 1.44.0, main
68eb8cc80
Node version
- v24.18.0
Additional context
Searches for ollama stop, ollama stopSequences, and stopSequences did not find an existing JS fix for this serialization path. AI assistance was used for the source investigation and reproduction.