litellmts-core 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handlers/ollama.js +14 -8
- package/dist/models/registry.js +7 -4
- package/package.json +1 -1
package/dist/handlers/ollama.js
CHANGED
|
@@ -53,12 +53,15 @@ async function* iterateResponse(response, model, prompt) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
async function getOllamaResponse(model, prompt, baseUrl, stream) {
|
|
56
|
+
async function getOllamaResponse(model, prompt, baseUrl, stream, apiKey) {
|
|
57
|
+
const headers = {
|
|
58
|
+
'Content-Type': 'application/json',
|
|
59
|
+
};
|
|
60
|
+
if (apiKey)
|
|
61
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
57
62
|
return fetch(`${baseUrl}/api/chat`, {
|
|
58
63
|
method: 'POST',
|
|
59
|
-
headers
|
|
60
|
-
'Content-Type': 'application/json',
|
|
61
|
-
},
|
|
64
|
+
headers,
|
|
62
65
|
body: JSON.stringify({
|
|
63
66
|
model,
|
|
64
67
|
messages: [{ role: 'user', content: prompt }],
|
|
@@ -72,7 +75,7 @@ async function OllamaHandler(params) {
|
|
|
72
75
|
? params.model.slice(7)
|
|
73
76
|
: params.model;
|
|
74
77
|
const prompt = (0, combinePrompts_1.combinePrompts)(params.messages);
|
|
75
|
-
const res = await getOllamaResponse(model, prompt, baseUrl, !!params.stream);
|
|
78
|
+
const res = await getOllamaResponse(model, prompt, baseUrl, !!params.stream, params.apiKey);
|
|
76
79
|
if (!res.ok) {
|
|
77
80
|
throw new Error(`Received an error with code ${res.status} from Ollama API.`);
|
|
78
81
|
}
|
|
@@ -89,13 +92,16 @@ async function OllamaHandler(params) {
|
|
|
89
92
|
return toResponse(message, model, prompt);
|
|
90
93
|
}
|
|
91
94
|
const registry_1 = require("../models/registry");
|
|
92
|
-
(0, registry_1.registerModelProvider)('ollama', async ({ baseUrl } = {}) => {
|
|
95
|
+
(0, registry_1.registerModelProvider)('ollama', async ({ baseUrl, apiKey } = {}) => {
|
|
93
96
|
const url = baseUrl ?? 'http://127.0.0.1:11434';
|
|
94
|
-
const
|
|
97
|
+
const headers = {};
|
|
98
|
+
if (apiKey)
|
|
99
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
100
|
+
const res = await fetch(`${url.replace(/\/+$/, '')}/api/tags`, { headers });
|
|
95
101
|
if (!res.ok)
|
|
96
102
|
return [];
|
|
97
103
|
const { models } = (await res.json());
|
|
98
|
-
return (models ?? []).map((m) => ({ id: m.name, provider: 'ollama' }));
|
|
104
|
+
return (models ?? []).map((m) => ({ id: m.name.replace(/-cloud$/, ''), provider: 'ollama' }));
|
|
99
105
|
});
|
|
100
106
|
const registry_2 = require("../registry");
|
|
101
107
|
(0, registry_2.registerCompletionHandler)('ollama/', OllamaHandler);
|
package/dist/models/registry.js
CHANGED
|
@@ -10,15 +10,18 @@ const CACHE_TTL = 5 * 60 * 1000;
|
|
|
10
10
|
function registerModelProvider(provider, fetcher) {
|
|
11
11
|
fetchers.set(provider, fetcher);
|
|
12
12
|
}
|
|
13
|
-
async function tryOllamaTags(baseUrl, provider) {
|
|
13
|
+
async function tryOllamaTags(baseUrl, provider, apiKey) {
|
|
14
14
|
try {
|
|
15
|
-
const
|
|
15
|
+
const headers = {};
|
|
16
|
+
if (apiKey)
|
|
17
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
18
|
+
const res = await fetch(`${baseUrl}/api/tags`, { headers });
|
|
16
19
|
if (!res.ok)
|
|
17
20
|
return null;
|
|
18
21
|
const { models } = (await res.json());
|
|
19
22
|
if (!Array.isArray(models))
|
|
20
23
|
return null;
|
|
21
|
-
return models.map((m) => ({ id: m.name, provider }));
|
|
24
|
+
return models.map((m) => ({ id: m.name.replace(/-cloud$/, ''), provider }));
|
|
22
25
|
}
|
|
23
26
|
catch {
|
|
24
27
|
return null;
|
|
@@ -48,7 +51,7 @@ async function listModels(provider, opts) {
|
|
|
48
51
|
let data = null;
|
|
49
52
|
if (opts?.baseUrl) {
|
|
50
53
|
const baseUrl = opts.baseUrl.replace(/\/+$/, '');
|
|
51
|
-
data = await tryOllamaTags(baseUrl, provider);
|
|
54
|
+
data = await tryOllamaTags(baseUrl, provider, opts.apiKey);
|
|
52
55
|
if (!data || data.length === 0) {
|
|
53
56
|
data = await tryOpenAIModels(baseUrl, provider, opts.apiKey);
|
|
54
57
|
}
|