Skip to content

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

Hold a first turn for Ollama's list, and say when a server isn't Ollama

milind-sonid404cfc2c5cb
diff --git a/server/drivers/ollama.test.ts b/server/drivers/ollama.test.ts
index 36b3659640..d808efb23f 100644
--- a/server/drivers/ollama.test.ts
+++ b/server/drivers/ollama.test.ts
@@ -263,6 +263,39 @@ describe("the chat engine on Ollama", () => {
} finally { await empty.dispose(); }
});
+ it("says so when a server added as Ollama answers as something else", async () => {
+ const { url } = await fakeOllama({ models: [LLAMA], tags: false });
+ const instance = await create({ url: `${url}/v1`, catalog: "ollama" });
+ try {
+ expect(await instance.snapshot()).toMatchObject({ state: "unavailable", reason: expect.stringContaining("it isn't Ollama"), ollama: { state: "unreachable", problem: "not-ollama" } });
+ } finally { await instance.dispose(); }
+ });
+
+ it("holds a first turn until the list says what its model can do", async () => {
+ const { url, chats } = await fakeOllama({ models: [GEMMA] });
+ const real = globalThis.fetch;
+ let release = () => {};
+ const held = new Promise<void>((resolve) => { release = resolve; });
+ vi.stubGlobal("fetch", (async (input, init) => {
+ if (String(input).endsWith("/api/show")) await held;
+ return real(input, init);
+ }) as typeof fetch);
+ const instance = await create({ url: `${url}/v1`, catalog: "ollama" });
+ const recorder = recordEvents(instance.adapter);
+ try {
+ const threadId = randomUUID();
+ const started = instance.adapter.sendTurn({ threadId, text: "hi", model: "gemma2:2b" });
+ release();
+ await started;
+ await recorder.until((event) => event.type === "turn.completed" && event.threadId === threadId);
+ expect(chats[0]!.tools).toBeUndefined();
+ } finally {
+ recorder.stop();
+ await instance.dispose();
+ vi.unstubAllGlobals();
+ }
+ });
+
it("recognises a server someone added as OpenAI-compatible, and keeps its saved key and model", async () => {
const { url } = await fakeOllama({ models: [LLAMA, GEMMA] });
const config = { url: `${url}/v1`, apiKeyEnv: "FIXTURE_KEY", model: "gemma2:2b" };
diff --git a/server/drivers/ollama.ts b/server/drivers/ollama.ts
index 32785d9ddf..ed729cedb0 100644
--- a/server/drivers/ollama.ts
+++ b/server/drivers/ollama.ts
@@ -135,12 +135,12 @@ export async function probeOllama(url: string, options: ProbeOptions = {}): Prom
}
/** What stops an Ollama from answering, for the engine list; null when it can, or when something else answers there. */
-export function ollamaUnavailable(status: OllamaStatus): string | null {
+export function ollamaUnavailable(status: OllamaStatus, addedAsOllama = false): string | null {
switch (status.state) {
case "ready": return null;
case "no-models": return `Ollama has no models yet. Run \`${OLLAMA_PULL_COMMAND}\`, then check again.`;
case "not-running": return `Ollama isn't running at ${status.url}. Open the Ollama app or run \`ollama serve\`.`;
- case "unreachable": return status.problem === "not-ollama" ? null
+ case "unreachable": return status.problem === "not-ollama" ? addedAsOllama ? `Something answers at ${status.url}, but it isn't Ollama.` : null
: `Can't reach Ollama at ${status.url}${status.problem === "timeout" ? ": it did not answer in time" : ""}. Check the address and that this computer can reach it.`;
}
}
diff --git a/server/drivers/openai-compat.ts b/server/drivers/openai-compat.ts
index f47d1debf2..e815f2465a 100644
--- a/server/drivers/openai-compat.ts
+++ b/server/drivers/openai-compat.ts
@@ -362,7 +362,7 @@ export const OpenAICompatDriver: ProviderDriver<OpenAICompatConfig> = {
serverUnavailable: async () => {
if (!isOllamaServer(config)) return null;
const status = await checkOllama();
- const reason = ollamaUnavailable(status);
+ const reason = ollamaUnavailable(status, config.catalog === "ollama");
return reason ? { reason, ollama: { state: status.state, url: status.url, ...(status.problem ? { problem: status.problem } : {}) } } : null;
},
} : {}),
@@ -397,6 +397,10 @@ export const OpenAICompatDriver: ProviderDriver<OpenAICompatConfig> = {
}),
},
});
+ if (loading && isOllamaServer(config)) {
+ const send = runtime.adapter.sendTurn;
+ runtime.adapter.sendTurn = async (turn) => { await loading; return send(turn); };
+ }
return openRouter && loading ? withOpenRouterTurns(runtime, loading) : runtime;
},
};
diff --git a/src/components/EngineSetup.test.ts b/src/components/EngineSetup.test.ts
index fb7ddbdd91..33e7870c35 100644
--- a/src/components/EngineSetup.test.ts
+++ b/src/components/EngineSetup.test.ts
@@ -375,6 +375,7 @@ describe("Ollama setup", () => {
const markup = renderToStaticMarkup(createElement(StoreProvider, null, createElement(EngineSetup, { instance: ollama })));
expect(markup).toContain('data-ollama-state="no-models"');
expect(markup).toContain("ollama pull llama3.2");
+ expect(markup).toContain("Check again");
expect(markup).not.toContain("Ollama has no models yet.");
});
});
diff --git a/src/components/EngineSetup.tsx b/src/components/EngineSetup.tsx
index 2d01e11c39..2e113a0b09 100644
--- a/src/components/EngineSetup.tsx
+++ b/src/components/EngineSetup.tsx
@@ -498,6 +498,17 @@ function ApiKeyEngineSetup({ instance, className, unframed, configured = false }
);
}
+function CheckEnginesAgain() {
+ const { refreshInstances } = useStore();
+ const [busy, setBusy] = useState(false);
+ return (
+ <button type="button" disabled={busy} className="ui-button" onClick={() => { setBusy(true); void refreshInstances().finally(() => setBusy(false)); }}>
+ {busy && <Loader2 size={12} className="animate-spin" aria-hidden="true" />}
+ {t("common.checkAgain")}
+ </button>
+ );
+}
+
export function ApiKeyEngineManage({ instance, className }: { instance: InstanceInfo; className?: string }) {
if (!hasSavedApiKey(instance)) return null;
return <ApiKeyEngineSetup instance={instance} className={className} unframed={false} configured />;
@@ -582,7 +593,7 @@ export function EngineSetup({
<div className={cn(!unframed && "rounded-xl border border-hairline/40 bg-control/30 p-3", className)}>
<div className="text-[13px] font-semibold text-ink">{t("engineSetup.notReady", { name: engineDisplayName(instance) })}</div>
{instance.snapshot.ollama
- ? <div className="mt-1"><OllamaStatusLine status={instance.snapshot.ollama} /></div>
+ ? <div className="mt-1 flex flex-col items-start gap-2"><OllamaStatusLine status={instance.snapshot.ollama} /><CheckEnginesAgain /></div>
: <p className="mt-1 text-[12px] leading-relaxed text-ink-secondary">
{instance.snapshot.authenticationUnavailableReason ?? instance.snapshot.reason ?? t("engineSetup.noReason")}
</p>}