@saltcorn/large-language-model 0.6.2 → 0.6.4
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 +5 -1
- package/index.js +36 -7
- package/package.json +1 -1
package/generate.js
CHANGED
|
@@ -77,7 +77,11 @@ const getCompletion = async (config, opts) => {
|
|
|
77
77
|
return await getCompletionOpenAICompatible(
|
|
78
78
|
{
|
|
79
79
|
chatCompleteEndpoint: opts?.endpoint || config.endpoint,
|
|
80
|
-
bearer:
|
|
80
|
+
bearer:
|
|
81
|
+
opts?.bearer ||
|
|
82
|
+
opts?.api_key ||
|
|
83
|
+
config.bearer_auth ||
|
|
84
|
+
config.bearer,
|
|
81
85
|
apiKey: opts?.api_key || config.api_key,
|
|
82
86
|
model: opts?.model || config.model,
|
|
83
87
|
},
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const db = require("@saltcorn/data/db");
|
|
|
5
5
|
const { getCompletion, getEmbedding } = require("./generate");
|
|
6
6
|
const { OPENAI_MODELS } = require("./constants.js");
|
|
7
7
|
const { eval_expression } = require("@saltcorn/data/models/expression");
|
|
8
|
+
const { interpolate } = require("@saltcorn/data/utils");
|
|
8
9
|
|
|
9
10
|
const configuration_workflow = () =>
|
|
10
11
|
new Workflow({
|
|
@@ -211,11 +212,12 @@ module.exports = {
|
|
|
211
212
|
if (mode === "workflow") {
|
|
212
213
|
return [
|
|
213
214
|
{
|
|
214
|
-
name: "
|
|
215
|
-
label: "Prompt
|
|
215
|
+
name: "prompt_template",
|
|
216
|
+
label: "Prompt",
|
|
216
217
|
sublabel:
|
|
217
|
-
"
|
|
218
|
+
"Prompt text. Use interpolations {{ }} to access variables in the context",
|
|
218
219
|
type: "String",
|
|
220
|
+
fieldview: "textarea",
|
|
219
221
|
required: true,
|
|
220
222
|
},
|
|
221
223
|
{
|
|
@@ -225,6 +227,13 @@ module.exports = {
|
|
|
225
227
|
type: "String",
|
|
226
228
|
required: true,
|
|
227
229
|
},
|
|
230
|
+
{
|
|
231
|
+
name: "chat_history_field",
|
|
232
|
+
label: "Chat history variable",
|
|
233
|
+
sublabel:
|
|
234
|
+
"Use this context variable to store the chat history for subsequent prompts",
|
|
235
|
+
type: "String",
|
|
236
|
+
},
|
|
228
237
|
...override_fields,
|
|
229
238
|
];
|
|
230
239
|
}
|
|
@@ -268,12 +277,16 @@ module.exports = {
|
|
|
268
277
|
configuration: {
|
|
269
278
|
prompt_field,
|
|
270
279
|
prompt_formula,
|
|
280
|
+
prompt_template,
|
|
271
281
|
answer_field,
|
|
272
282
|
override_config,
|
|
283
|
+
chat_history_field,
|
|
273
284
|
},
|
|
274
285
|
}) => {
|
|
275
286
|
let prompt;
|
|
276
|
-
if (
|
|
287
|
+
if (mode === "workflow")
|
|
288
|
+
prompt = interpolate(prompt_template, row, user);
|
|
289
|
+
else if (prompt_field === "Formula" || mode === "workflow")
|
|
277
290
|
prompt = eval_expression(
|
|
278
291
|
prompt_formula,
|
|
279
292
|
row,
|
|
@@ -291,9 +304,25 @@ module.exports = {
|
|
|
291
304
|
opts.api_key = altcfg.api_key;
|
|
292
305
|
opts.bearer = altcfg.bearer;
|
|
293
306
|
}
|
|
294
|
-
|
|
295
|
-
if (
|
|
296
|
-
|
|
307
|
+
let history = [];
|
|
308
|
+
if (chat_history_field && row[chat_history_field]) {
|
|
309
|
+
history = row[chat_history_field];
|
|
310
|
+
}
|
|
311
|
+
const ans = await getCompletion(config, {
|
|
312
|
+
prompt,
|
|
313
|
+
chat: history,
|
|
314
|
+
...opts,
|
|
315
|
+
});
|
|
316
|
+
const upd = { [answer_field]: ans };
|
|
317
|
+
if (chat_history_field) {
|
|
318
|
+
upd[chat_history_field] = [
|
|
319
|
+
...history,
|
|
320
|
+
{ role: "user", content: prompt },
|
|
321
|
+
{ role: "system", content: ans },
|
|
322
|
+
];
|
|
323
|
+
}
|
|
324
|
+
if (mode === "workflow") return upd;
|
|
325
|
+
else await table.updateRow(upd, row[table.pk_name]);
|
|
297
326
|
},
|
|
298
327
|
},
|
|
299
328
|
}),
|