Skip to content

Commit 22327a5

Browse files
committed
fix(ollama): normalize model endpoint ownership
1 parent 0618f31 commit 22327a5

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎extensions/ollama/src/stream-runtime.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,40 @@ describe("createConfiguredOllamaStreamFn", () => {
33533353
);
33543354
});
33553355

3356+
it("acquires the provider service when model baseUrl is whitespace", async () => {
3357+
await withMockNdjsonFetch(
3358+
[
3359+
'{"model":"m","created_at":"t","message":{"role":"assistant","content":"ok"},"done":false}',
3360+
'{"model":"m","created_at":"t","message":{"role":"assistant","content":""},"done":true,"prompt_eval_count":1,"eval_count":1}',
3361+
],
3362+
async (fetchMock) => {
3363+
const acquire = vi.fn(async () => ({ release: vi.fn() }));
3364+
const streamFn = createConfiguredOllamaStreamFn({
3365+
model: { baseUrl: " " },
3366+
localService: { providerId: "ollama-gpu", acquire },
3367+
});
3368+
const stream = await Promise.resolve(
3369+
streamFn(
3370+
{
3371+
id: "qwen3:32b",
3372+
api: "ollama",
3373+
provider: "ollama-gpu",
3374+
contextWindow: 131072,
3375+
} as never,
3376+
{ messages: [{ role: "user", content: "hello" }] } as never,
3377+
{} as never,
3378+
),
3379+
);
3380+
3381+
const events = await collectStreamEvents(stream);
3382+
3383+
expect(events.at(-1)).toMatchObject({ type: "done" });
3384+
expect(acquire).toHaveBeenCalledOnce();
3385+
expect(getGuardedFetchCall(fetchMock).url).toBe("http://127.0.0.1:11434/api/chat");
3386+
},
3387+
);
3388+
});
3389+
33563390
it("uses provider-level baseUrl when model baseUrl is absent", async () => {
33573391
await withMockNdjsonFetch(
33583392
[

‎extensions/ollama/src/stream.runtime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ export function createConfiguredOllamaStreamFn(params: {
14191419
localService?: OllamaLocalService;
14201420
providerBaseUrl?: string;
14211421
}): StreamFn {
1422-
const modelBaseUrl = readStringValue(params.model.baseUrl);
1422+
const modelBaseUrl = readStringValue(params.model.baseUrl)?.trim();
14231423
const baseUrl = resolveOllamaBaseUrlForRun({
14241424
modelBaseUrl,
14251425
providerBaseUrl: params.providerBaseUrl,

0 commit comments

Comments
 (0)