Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(ollama): a cloud model runs at its own window, with no -omb copy

Absterrg04d1f98ccf977
diff --git a/server/drivers/ollama-context.test.ts b/server/drivers/ollama-context.test.ts
index 703aff83aa..3eb98e65f4 100644
--- a/server/drivers/ollama-context.test.ts
+++ b/server/drivers/ollama-context.test.ts
@@ -137,12 +137,24 @@ describe("serveWithWindow", () => {
expect(lab.created).toHaveLength(1);
});
- it("leaves a cloud model alone", async () => {
+ it("leaves a model that runs on another host alone", async () => {
const lab = ollama({ show: { remote_host: "https://ollama.com" } });
- expect(await serveWithWindow(ORIGIN, "glm-5:cloud", lab.server)).toEqual({ model: "glm-5:cloud" });
+ expect(await serveWithWindow(ORIGIN, "glm-5:latest", lab.server)).toEqual({ model: "glm-5:latest" });
expect(lab.created).toEqual([]);
});
+ it.each(["gemma4:cloud", "deepseek-v4.1-flash:1017-cloud"])("leaves %s alone, at the window it was trained on", async (model) => {
+ // Ollama v0.40.16 answers /api/show for a cloud name from ollama.com, with no remote_host or remote_model.
+ const lab = ollama({ show: { model_info: { "deepseek_v41.context_length": 1_048_576 }, capabilities: ["completion", "tools"] } });
+ expect(await serveWithWindow(ORIGIN, model, lab.server)).toEqual({ model, window: 1_048_576 });
+ expect(lab.created).toEqual([]);
+ });
+
+ it("still makes a window for a local model whose tag only mentions the cloud", async () => {
+ const lab = ollama();
+ expect((await serveWithWindow(ORIGIN, "wordcloud:7b", lab.server, 24 * GB)).model).toMatch(/^wordcloud:7b-omb-\d+k$/);
+ });
+
it.each([
["a refused create", ollama({ createStatus: 500 }).server],
["a dead server", (async () => { throw new Error("ECONNREFUSED"); }) as unknown as typeof fetch],
diff --git a/server/drivers/ollama-context.ts b/server/drivers/ollama-context.ts
index 27dae1de7d..cc073d9912 100644
--- a/server/drivers/ollama-context.ts
+++ b/server/drivers/ollama-context.ts
@@ -17,6 +17,10 @@ const nameFor = (model: string, window: number) => `${model.includes(":") ? mode
export const isContextName = (model: string) => SUFFIX.test(model);
+/** Ollama's own rule (internal/modelref, v0.40.16): a tag of `cloud`, or one ending in `-cloud`, runs on ollama.com, whose
+ * /api/show answer carries no remote_host or remote_model. */
+const CLOUD_TAG = /:(?:[^:/]*-)?cloud$/i;
+
/** The name a person picked, for one of ours coming back in a server's lists. */
export const pickedName = (model: string) => model.replace(SUFFIX, "");
@@ -69,7 +73,7 @@ const post = (body: unknown): RequestInit => ({ method: "POST", headers: { "cont
async function decide(origin: string, model: string, fetchImpl: typeof fetch, memoryBytes: number | undefined): Promise<ServedModel> {
const facts = showFacts(await json(fetchImpl, `${origin}/api/show`, post({ model }), 3_000));
- if (facts.remote) return { model };
+ if (facts.remote || CLOUD_TAG.test(model)) return { model, ...(facts.trained ? { window: facts.trained } : {}) };
if (facts.pinned) return { model, window: facts.pinned };
const running = await json(fetchImpl, `${origin}/api/ps`, {}, 3_000).catch(() => null) as { models?: Array<{ name?: unknown; model?: unknown; context_length?: unknown }> } | null;
const loaded = running?.models?.find((entry) => entry.name === model || entry.model === model || entry.name === `${model}:latest`)?.context_length;