

























@@ -94,6 +94,7 @@ describe("createConfiguredOllamaCompatStreamWrapper", () => {
9494provider: "ollama",
9595id: "kimi-k2.5:cloud",
9696contextWindow: 262144,
97+params: { num_ctx: 65536 },
9798};
989999100const wrapped = createConfiguredOllamaCompatStreamWrapper({
@@ -117,7 +118,43 @@ describe("createConfiguredOllamaCompatStreamWrapper", () => {
117118118119expect(patchedPayload).toMatchObject({
119120thinking: { type: "enabled" },
120-options: { num_ctx: 262144 },
121+options: { num_ctx: 65536 },
122+});
123+});
124+125+it("falls back to contextWindow when configured num_ctx is invalid", async () => {
126+let patchedPayload: Record<string, unknown> | undefined;
127+const baseStreamFn = vi.fn((_model, _context, options) => {
128+options?.onPayload?.({});
129+return (async function* () {})();
130+});
131+const model = {
132+api: "openai-completions",
133+provider: "ollama",
134+id: "qwen3:32b",
135+contextWindow: 131072,
136+params: { num_ctx: 0 },
137+};
138+139+const wrapped = createConfiguredOllamaCompatStreamWrapper({
140+provider: "ollama",
141+modelId: "qwen3:32b",
142+ model,
143+streamFn: baseStreamFn,
144+} as never);
145+146+await wrapped?.(
147+model as never,
148+{ messages: [] } as never,
149+{
150+onPayload: (payload: unknown) => {
151+patchedPayload = payload as Record<string, unknown>;
152+},
153+} as never,
154+);
155+156+expect(patchedPayload).toMatchObject({
157+options: { num_ctx: 131072 },
121158});
122159});
123160@@ -878,6 +915,7 @@ function getGuardedFetchCall(fetchMock: typeof fetchWithSsrFGuardMock): GuardedF
878915async function createOllamaTestStream(params: {
879916baseUrl: string;
880917defaultHeaders?: Record<string, string>;
918+model?: Record<string, unknown>;
881919options?: {
882920apiKey?: string;
883921maxTokens?: number;
@@ -892,6 +930,7 @@ async function createOllamaTestStream(params: {
892930api: "ollama",
893931provider: "custom-ollama",
894932contextWindow: 131072,
933+ ...params.model,
895934} as unknown as Parameters<typeof streamFn>[0],
896935{
897936messages: [{ role: "user", content: "hello" }],
@@ -1157,6 +1196,33 @@ describe("createOllamaStreamFn", () => {
11571196);
11581197});
115911981199+it("uses configured params.num_ctx for native Ollama chat options", async () => {
1200+await withMockNdjsonFetch(
1201+[
1202+'{"model":"m","created_at":"t","message":{"role":"assistant","content":"ok"},"done":false}',
1203+'{"model":"m","created_at":"t","message":{"role":"assistant","content":""},"done":true,"prompt_eval_count":1,"eval_count":1}',
1204+],
1205+async (fetchMock) => {
1206+const stream = await createOllamaTestStream({
1207+baseUrl: "http://ollama-host:11434",
1208+model: { params: { num_ctx: 32768 }, contextWindow: 131072 },
1209+});
1210+1211+const events = await collectStreamEvents(stream);
1212+expect(events.at(-1)?.type).toBe("done");
1213+1214+const requestInit = getGuardedFetchCall(fetchMock).init ?? {};
1215+if (typeof requestInit.body !== "string") {
1216+throw new Error("Expected string request body");
1217+}
1218+const requestBody = JSON.parse(requestInit.body) as {
1219+options: { num_ctx?: number };
1220+};
1221+expect(requestBody.options.num_ctx).toBe(32768);
1222+},
1223+);
1224+});
1225+11601226it("uses the default loopback policy when baseUrl is empty", async () => {
11611227await withMockNdjsonFetch(
11621228[
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。