


























@@ -292,6 +292,113 @@ describe("createConfiguredOllamaCompatStreamWrapper", () => {
292292);
293293});
294294295+it("does not forward truthy configured native Ollama thinking for non-reasoning models", async () => {
296+await withMockNdjsonFetch(
297+[
298+'{"model":"m","created_at":"t","message":{"role":"assistant","content":"ok"},"done":false}',
299+'{"model":"m","created_at":"t","message":{"role":"assistant","content":""},"done":true,"prompt_eval_count":1,"eval_count":1}',
300+],
301+async (fetchMock) => {
302+const baseStreamFn = createOllamaStreamFn("http://ollama-host:11434");
303+const model = {
304+api: "ollama",
305+provider: "ollama",
306+id: "llama3.2:latest",
307+contextWindow: 8192,
308+reasoning: false,
309+params: { thinking: "medium" },
310+};
311+312+const wrapped = createConfiguredOllamaCompatStreamWrapper({
313+provider: "ollama",
314+modelId: "llama3.2:latest",
315+ model,
316+streamFn: baseStreamFn,
317+thinkingLevel: "off",
318+} as never);
319+if (!wrapped) {
320+throw new Error("Expected wrapped Ollama stream function");
321+}
322+323+const stream = await Promise.resolve(
324+wrapped(
325+model as never,
326+{
327+messages: [{ role: "user", content: "hello" }],
328+} as never,
329+{} as never,
330+),
331+);
332+333+await collectStreamEvents(stream);
334+335+const requestInit = getGuardedFetchCall(fetchMock).init ?? {};
336+if (typeof requestInit.body !== "string") {
337+throw new Error("Expected string request body");
338+}
339+const requestBody = JSON.parse(requestInit.body) as {
340+think?: string;
341+options?: { think?: string };
342+};
343+expect(requestBody.think).toBeUndefined();
344+expect(requestBody.options?.think).toBeUndefined();
345+},
346+);
347+});
348+349+it("does not forward runtime native Ollama thinking for non-reasoning models", async () => {
350+await withMockNdjsonFetch(
351+[
352+'{"model":"m","created_at":"t","message":{"role":"assistant","content":"ok"},"done":false}',
353+'{"model":"m","created_at":"t","message":{"role":"assistant","content":""},"done":true,"prompt_eval_count":1,"eval_count":1}',
354+],
355+async (fetchMock) => {
356+const baseStreamFn = createOllamaStreamFn("http://ollama-host:11434");
357+const model = {
358+api: "ollama",
359+provider: "ollama",
360+id: "llama3.2:latest",
361+contextWindow: 8192,
362+reasoning: false,
363+};
364+365+const wrapped = createConfiguredOllamaCompatStreamWrapper({
366+provider: "ollama",
367+modelId: "llama3.2:latest",
368+ model,
369+streamFn: baseStreamFn,
370+thinkingLevel: "low",
371+} as never);
372+if (!wrapped) {
373+throw new Error("Expected wrapped Ollama stream function");
374+}
375+376+const stream = await Promise.resolve(
377+wrapped(
378+model as never,
379+{
380+messages: [{ role: "user", content: "hello" }],
381+} as never,
382+{} as never,
383+),
384+);
385+386+await collectStreamEvents(stream);
387+388+const requestInit = getGuardedFetchCall(fetchMock).init ?? {};
389+if (typeof requestInit.body !== "string") {
390+throw new Error("Expected string request body");
391+}
392+const requestBody = JSON.parse(requestInit.body) as {
393+think?: string;
394+options?: { think?: string };
395+};
396+expect(requestBody.think).toBeUndefined();
397+expect(requestBody.options?.think).toBeUndefined();
398+},
399+);
400+});
401+295402it("forwards the native think effort on native Ollama chat requests when thinking is enabled", async () => {
296403await withMockNdjsonFetch(
297404[
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。