Skip to content

Commit

Permalink
Send ollama pull request if model is not available locally (#1227)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin authored May 30, 2024
1 parent b812eea commit d58c7e3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lib/server/endpoints/ollama/endpointOllama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ export function endpointOllama(input: z.input<typeof endpointOllamaParametersSch

const parameters = { ...model.parameters, ...generateSettings };

const requestInfo = await fetch(`${url}/api/tags`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});

const tags = await requestInfo.json();

if (!tags.models.some((m: { name: string }) => m.name === ollamaName)) {
// if its not in the tags, pull but dont wait for the answer
fetch(`${url}/api/pull`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: ollamaName ?? model.name,
stream: false,
}),
});

throw new Error("Currently pulling model from Ollama, please try again later.");
}

const r = await fetch(`${url}/api/generate`, {
method: "POST",
headers: {
Expand Down

0 comments on commit d58c7e3

Please sign in to comment.