fix(ollama): guard against reasoning="off" truthy string, add test case

- Check `options.reasoning !== "off"` before setting think: true
- Simplify else-if to just `else if (options)`
- Add test: reasoning="off" → think: false

Addresses review feedback from greptile-apps, codex-connector, and @Kaspre
This commit is contained in:
杨艺韬(yangyitao) 2026-03-21 02:27:10 +00:00
parent aac1c913d3
commit 2092d1a73b
2 changed files with 29 additions and 2 deletions

View File

@ -598,6 +598,33 @@ describe("createOllamaStreamFn", () => {
},
);
});
it("sends think:false when reasoning is 'off'", async () => {
await withMockNdjsonFetch(
[
'{"model":"m","created_at":"t","message":{"role":"assistant","content":"ok"},"done":false}',
'{"model":"m","created_at":"t","message":{"role":"assistant","content":""},"done":true,"prompt_eval_count":1,"eval_count":1}',
],
async (fetchMock) => {
const streamFn = createOllamaStreamFn("http://ollama-host:11434");
const stream = await streamFn(
{
id: "deepseek-r1:32b",
api: "ollama",
provider: "ollama",
contextWindow: 131072,
} as never,
{ messages: [{ role: "user", content: "hello" }] } as never,
{ reasoning: "off" } as never,
);
await collectStreamEvents(stream);
const [, reqInit] = fetchMock.mock.calls[0] as unknown as [string, RequestInit];
const body = JSON.parse(reqInit.body as string) as { think?: boolean };
expect(body.think).toBe(false);
},
);
});
});
describe("resolveOllamaBaseUrlForRun", () => {

View File

@ -464,9 +464,9 @@ export function createOllamaStreamFn(
// `think` boolean. Forward the reasoning level so `think: false` is
// sent explicitly when thinking is disabled (#46680).
const thinkParam: { think?: boolean } = {};
if (options?.reasoning) {
if (options?.reasoning && options.reasoning !== "off") {
thinkParam.think = true;
} else if (options && !options.reasoning) {
} else if (options) {
// Thinking explicitly disabled tell Ollama not to think.
thinkParam.think = false;
}