nsarrazin HF Staff commited on
Commit
30a5447
·
unverified ·
1 Parent(s): fd7f926

Send `ollama pull` request if model is not available locally (#1227)

Browse files
src/lib/server/endpoints/ollama/endpointOllama.ts CHANGED
@@ -24,6 +24,31 @@ export function endpointOllama(input: z.input<typeof endpointOllamaParametersSch
24
 
25
  const parameters = { ...model.parameters, ...generateSettings };
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  const r = await fetch(`${url}/api/generate`, {
28
  method: "POST",
29
  headers: {
 
24
 
25
  const parameters = { ...model.parameters, ...generateSettings };
26
 
27
+ const requestInfo = await fetch(`${url}/api/tags`, {
28
+ method: "GET",
29
+ headers: {
30
+ "Content-Type": "application/json",
31
+ },
32
+ });
33
+
34
+ const tags = await requestInfo.json();
35
+
36
+ if (!tags.models.some((m: { name: string }) => m.name === ollamaName)) {
37
+ // if its not in the tags, pull but dont wait for the answer
38
+ fetch(`${url}/api/pull`, {
39
+ method: "POST",
40
+ headers: {
41
+ "Content-Type": "application/json",
42
+ },
43
+ body: JSON.stringify({
44
+ name: ollamaName ?? model.name,
45
+ stream: false,
46
+ }),
47
+ });
48
+
49
+ throw new Error("Currently pulling model from Ollama, please try again later.");
50
+ }
51
+
52
  const r = await fetch(`${url}/api/generate`, {
53
  method: "POST",
54
  headers: {