@saltcorn/large-language-model 1.0.10 → 1.0.11
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 -0
- package/index.js +2 -0
- package/package.json +1 -1
package/generate.js
CHANGED
|
@@ -198,6 +198,31 @@ const getAudioTranscription = async (
|
|
|
198
198
|
|
|
199
199
|
const last = (xs) => xs[xs.length - 1];
|
|
200
200
|
|
|
201
|
+
const genericResponse = async (
|
|
202
|
+
{ backend, apiKey, api_key, provider, ai_sdk_provider, responses_api },
|
|
203
|
+
role,
|
|
204
|
+
prompt,
|
|
205
|
+
opts,
|
|
206
|
+
) => {
|
|
207
|
+
let chat = opts.chat;
|
|
208
|
+
let result = opts.prompt;
|
|
209
|
+
//console.log("chat", JSON.stringify(chat, null, 2));
|
|
210
|
+
switch (opts.backend || backend) {
|
|
211
|
+
case "AI SDK":
|
|
212
|
+
if (role === "assistant" && typeof prompt === "string")
|
|
213
|
+
opts.chat.push({
|
|
214
|
+
role,
|
|
215
|
+
content: [{
|
|
216
|
+
type: "text",
|
|
217
|
+
text: prompt,
|
|
218
|
+
}],
|
|
219
|
+
});
|
|
220
|
+
break;
|
|
221
|
+
default:
|
|
222
|
+
opts.chat.push({ role, content: prompt });
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
201
226
|
const toolResponse = async (
|
|
202
227
|
{ backend, apiKey, api_key, provider, ai_sdk_provider, responses_api },
|
|
203
228
|
opts,
|
|
@@ -1324,5 +1349,6 @@ module.exports = {
|
|
|
1324
1349
|
getImageGeneration,
|
|
1325
1350
|
getAudioTranscription,
|
|
1326
1351
|
toolResponse,
|
|
1352
|
+
genericResponse,
|
|
1327
1353
|
addImageMesssage,
|
|
1328
1354
|
};
|
package/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
getAudioTranscription,
|
|
14
14
|
toolResponse,
|
|
15
15
|
addImageMesssage,
|
|
16
|
+
genericResponse,
|
|
16
17
|
} = require("./generate");
|
|
17
18
|
const { OPENAI_MODELS } = require("./constants.js");
|
|
18
19
|
const { eval_expression } = require("@saltcorn/data/models/expression");
|
|
@@ -525,6 +526,7 @@ const functions = (config) => {
|
|
|
525
526
|
case "image":
|
|
526
527
|
return await addImageMesssage(config, { prompt, ...opts });
|
|
527
528
|
default:
|
|
529
|
+
return genericResponse(config, what, prompt, opts);
|
|
528
530
|
break;
|
|
529
531
|
}
|
|
530
532
|
},
|