@saltcorn/large-language-model 0.6.0 → 0.6.2
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/index.js +59 -39
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const Workflow = require("@saltcorn/data/models/workflow");
|
|
2
2
|
const Form = require("@saltcorn/data/models/form");
|
|
3
|
+
const FieldRepeat = require("@saltcorn/data/models/fieldrepeat");
|
|
3
4
|
const db = require("@saltcorn/data/db");
|
|
4
5
|
const { getCompletion, getEmbedding } = require("./generate");
|
|
5
6
|
const { OPENAI_MODELS } = require("./constants.js");
|
|
@@ -81,6 +82,12 @@ const configuration_workflow = () =>
|
|
|
81
82
|
type: "String",
|
|
82
83
|
showIf: { backend: "OpenAI-compatible API" },
|
|
83
84
|
},
|
|
85
|
+
{
|
|
86
|
+
name: "api_key",
|
|
87
|
+
label: "API key",
|
|
88
|
+
type: "String",
|
|
89
|
+
showIf: { backend: "OpenAI-compatible API" },
|
|
90
|
+
},
|
|
84
91
|
{
|
|
85
92
|
name: "model",
|
|
86
93
|
label: "Model",
|
|
@@ -115,6 +122,39 @@ const configuration_workflow = () =>
|
|
|
115
122
|
"Optional. Example: http://localhost:11434/api/embeddings",
|
|
116
123
|
showIf: { backend: "Local Ollama" },
|
|
117
124
|
},
|
|
125
|
+
{
|
|
126
|
+
input_type: "section_header",
|
|
127
|
+
label: "Alternative configurations",
|
|
128
|
+
showIf: { backend: "OpenAI-compatible API" },
|
|
129
|
+
},
|
|
130
|
+
new FieldRepeat({
|
|
131
|
+
name: "altconfigs",
|
|
132
|
+
label: "Alternative configurations",
|
|
133
|
+
showIf: { backend: "OpenAI-compatible API" },
|
|
134
|
+
fields: [
|
|
135
|
+
{ name: "name", label: "Configuration name", type: "String" },
|
|
136
|
+
{
|
|
137
|
+
name: "model",
|
|
138
|
+
label: "Model",
|
|
139
|
+
type: "String",
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "endpoint",
|
|
143
|
+
label: "Endpoint",
|
|
144
|
+
type: "String",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "bearer_auth",
|
|
148
|
+
label: "Bearer Auth",
|
|
149
|
+
type: "String",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "api_key",
|
|
153
|
+
label: "API key",
|
|
154
|
+
type: "String",
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
}),
|
|
118
158
|
],
|
|
119
159
|
});
|
|
120
160
|
},
|
|
@@ -155,37 +195,18 @@ module.exports = {
|
|
|
155
195
|
llm_generate: {
|
|
156
196
|
requireRow: true,
|
|
157
197
|
configFields: ({ table, mode }) => {
|
|
158
|
-
const override_fields =
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
{
|
|
171
|
-
name: "override_model",
|
|
172
|
-
label: "Model",
|
|
173
|
-
type: "String",
|
|
174
|
-
showIf: { override_config: true },
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
name: "override_apikey",
|
|
178
|
-
label: "API key",
|
|
179
|
-
type: "String",
|
|
180
|
-
showIf: { override_config: true },
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
name: "override_bearer",
|
|
184
|
-
label: "Bearer",
|
|
185
|
-
type: "String",
|
|
186
|
-
showIf: { override_config: true },
|
|
187
|
-
},
|
|
188
|
-
];
|
|
198
|
+
const override_fields =
|
|
199
|
+
config.backend === "OpenAI-compatible API" &&
|
|
200
|
+
(config.altconfigs || []).filter((c) => c.name).length
|
|
201
|
+
? [
|
|
202
|
+
{
|
|
203
|
+
name: "override_config",
|
|
204
|
+
label: "Alternative LLM configuration",
|
|
205
|
+
type: "String",
|
|
206
|
+
attributes: { options: config.altconfigs.map((c) => c.name) },
|
|
207
|
+
},
|
|
208
|
+
]
|
|
209
|
+
: [];
|
|
189
210
|
|
|
190
211
|
if (mode === "workflow") {
|
|
191
212
|
return [
|
|
@@ -249,10 +270,6 @@ module.exports = {
|
|
|
249
270
|
prompt_formula,
|
|
250
271
|
answer_field,
|
|
251
272
|
override_config,
|
|
252
|
-
override_endpoint,
|
|
253
|
-
override_model,
|
|
254
|
-
override_apikey,
|
|
255
|
-
override_bearer,
|
|
256
273
|
},
|
|
257
274
|
}) => {
|
|
258
275
|
let prompt;
|
|
@@ -266,10 +283,13 @@ module.exports = {
|
|
|
266
283
|
else prompt = row[prompt_field];
|
|
267
284
|
const opts = {};
|
|
268
285
|
if (override_config) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
opts.
|
|
286
|
+
const altcfg = config.altconfigs.find(
|
|
287
|
+
(c) => c.name === override_config
|
|
288
|
+
);
|
|
289
|
+
opts.endpoint = altcfg.endpoint;
|
|
290
|
+
opts.model = altcfg.model;
|
|
291
|
+
opts.api_key = altcfg.api_key;
|
|
292
|
+
opts.bearer = altcfg.bearer;
|
|
273
293
|
}
|
|
274
294
|
const ans = await getCompletion(config, { prompt, ...opts });
|
|
275
295
|
if (mode === "workflow") return { [answer_field]: ans };
|