Skip to content

Commit

Permalink
Adjust how ollama status is checked
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethWussmann committed Oct 27, 2024
1 parent a05f05f commit e4ecf1f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/lib/ollama-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { ChatRequest, GenerateRequest, Ollama } from "ollama/browser";
import { settings, settingsStore } from "./settings";

export const getClient = () => {
const getOllamaUrl = () => {
const localStorageHost = localStorage.getItem("settings.ai.ollamaUrl");
const host = localStorageHost
? JSON.parse(localStorageHost)
: settingsStore.get(settings.ai.ollamaUrl);

return new Ollama({
host,
});
return host;
};

export const getClient = () =>
new Ollama({
host: getOllamaUrl(),
});

export const getModels = async () => {
const { models } = await getClient().list();
return models;
Expand Down Expand Up @@ -40,9 +43,13 @@ export const chat = async (request: ChatRequest) => {

export const isOllamaOnline = async () => {
try {
await getModels();
return true;
const response = await fetch(getOllamaUrl());
const text = await response.text();
if (response.ok && text.includes("Ollama")) {
return true;
}
} catch {
return false;
//
}
return false;
};

0 comments on commit e4ecf1f

Please sign in to comment.