@saltcorn/large-language-model 0.4.8 → 0.5.0
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/generate.js +26 -14
- package/package.json +1 -1
package/generate.js
CHANGED
|
@@ -13,17 +13,22 @@ const getEmbedding = async (config, opts) => {
|
|
|
13
13
|
return await getEmbeddingOpenAICompatible(
|
|
14
14
|
{
|
|
15
15
|
embeddingsEndpoint: "https://api.openai.com/v1/embeddings",
|
|
16
|
-
bearer: config.api_key,
|
|
17
|
-
embed_model: config.embed_model,
|
|
16
|
+
bearer: opts?.api_key || config.api_key,
|
|
17
|
+
embed_model: opts?.model || config.embed_model,
|
|
18
18
|
},
|
|
19
19
|
opts
|
|
20
20
|
);
|
|
21
21
|
case "OpenAI-compatible API":
|
|
22
22
|
return await getEmbeddingOpenAICompatible(
|
|
23
23
|
{
|
|
24
|
-
embeddingsEndpoint: config.embed_endpoint,
|
|
25
|
-
bearer: config.api_key,
|
|
26
|
-
|
|
24
|
+
embeddingsEndpoint: opts?.endpoint || config.embed_endpoint,
|
|
25
|
+
bearer: opts?.bearer || opts?.api_key || config.api_key,
|
|
26
|
+
apiKey: opts?.api_key || config.api_key,
|
|
27
|
+
embed_model:
|
|
28
|
+
opts?.embed_model ||
|
|
29
|
+
opts?.model ||
|
|
30
|
+
config.embed_model ||
|
|
31
|
+
config.model,
|
|
27
32
|
},
|
|
28
33
|
opts
|
|
29
34
|
);
|
|
@@ -32,7 +37,11 @@ const getEmbedding = async (config, opts) => {
|
|
|
32
37
|
return await getEmbeddingOpenAICompatible(
|
|
33
38
|
{
|
|
34
39
|
embeddingsEndpoint: config.embed_endpoint,
|
|
35
|
-
embed_model:
|
|
40
|
+
embed_model:
|
|
41
|
+
opts?.embed_model ||
|
|
42
|
+
opts?.model ||
|
|
43
|
+
config.embed_model ||
|
|
44
|
+
config.model,
|
|
36
45
|
},
|
|
37
46
|
opts
|
|
38
47
|
);
|
|
@@ -59,17 +68,18 @@ const getCompletion = async (config, opts) => {
|
|
|
59
68
|
return await getCompletionOpenAICompatible(
|
|
60
69
|
{
|
|
61
70
|
chatCompleteEndpoint: "https://api.openai.com/v1/chat/completions",
|
|
62
|
-
bearer: config.api_key,
|
|
63
|
-
model: config.model,
|
|
71
|
+
bearer: opts?.api_key || opts?.bearer || config.api_key,
|
|
72
|
+
model: opts?.model || config.model,
|
|
64
73
|
},
|
|
65
74
|
opts
|
|
66
75
|
);
|
|
67
76
|
case "OpenAI-compatible API":
|
|
68
77
|
return await getCompletionOpenAICompatible(
|
|
69
78
|
{
|
|
70
|
-
chatCompleteEndpoint: config.endpoint,
|
|
71
|
-
bearer: config.bearer,
|
|
72
|
-
|
|
79
|
+
chatCompleteEndpoint: opts?.endpoint || config.endpoint,
|
|
80
|
+
bearer: opts?.bearer || opts?.api_key || config.bearer,
|
|
81
|
+
apiKey: opts?.api_key || config.api_key,
|
|
82
|
+
model: opts?.model || config.model,
|
|
73
83
|
},
|
|
74
84
|
opts
|
|
75
85
|
);
|
|
@@ -80,7 +90,7 @@ const getCompletion = async (config, opts) => {
|
|
|
80
90
|
|
|
81
91
|
const ollama = new Ollama();
|
|
82
92
|
const olres = await ollama.generate({
|
|
83
|
-
model: config.model,
|
|
93
|
+
model: opts?.model || config.model,
|
|
84
94
|
...opts,
|
|
85
95
|
});
|
|
86
96
|
//console.log("the response ", olres);
|
|
@@ -109,7 +119,7 @@ const getCompletion = async (config, opts) => {
|
|
|
109
119
|
};
|
|
110
120
|
|
|
111
121
|
const getCompletionOpenAICompatible = async (
|
|
112
|
-
{ chatCompleteEndpoint, bearer, model },
|
|
122
|
+
{ chatCompleteEndpoint, bearer, apiKey, model },
|
|
113
123
|
{ systemPrompt, prompt, temperature, debugResult, chat = [], ...rest }
|
|
114
124
|
) => {
|
|
115
125
|
const headers = {
|
|
@@ -117,6 +127,7 @@ const getCompletionOpenAICompatible = async (
|
|
|
117
127
|
Accept: "application/json",
|
|
118
128
|
};
|
|
119
129
|
if (bearer) headers.Authorization = "Bearer " + bearer;
|
|
130
|
+
if (apiKey) headers["api-key"] = apiKey;
|
|
120
131
|
const body = {
|
|
121
132
|
//prompt: "How are you?",
|
|
122
133
|
model: rest.model || model,
|
|
@@ -154,12 +165,13 @@ const getEmbeddingOpenAICompatible = async (
|
|
|
154
165
|
config,
|
|
155
166
|
{ prompt, model, debugResult }
|
|
156
167
|
) => {
|
|
157
|
-
const { embeddingsEndpoint, bearer, embed_model } = config;
|
|
168
|
+
const { embeddingsEndpoint, bearer, apiKey, embed_model } = config;
|
|
158
169
|
const headers = {
|
|
159
170
|
"Content-Type": "application/json",
|
|
160
171
|
Accept: "application/json",
|
|
161
172
|
};
|
|
162
173
|
if (bearer) headers.Authorization = "Bearer " + bearer;
|
|
174
|
+
if (apiKey) headers["api-key"] = apiKey;
|
|
163
175
|
const body = {
|
|
164
176
|
//prompt: "How are you?",
|
|
165
177
|
model: model || embed_model || "text-embedding-3-small",
|