@saltcorn/large-language-model 0.8.5 → 0.8.7
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 +33 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const Workflow = require("@saltcorn/data/models/workflow");
|
|
2
2
|
const Form = require("@saltcorn/data/models/form");
|
|
3
3
|
const File = require("@saltcorn/data/models/file");
|
|
4
|
+
const User = require("@saltcorn/data/models/user");
|
|
4
5
|
const FieldRepeat = require("@saltcorn/data/models/fieldrepeat");
|
|
5
6
|
const Plugin = require("@saltcorn/data/models/plugin");
|
|
6
7
|
const { domReady } = require("@saltcorn/markup/tags");
|
|
@@ -594,7 +595,27 @@ module.exports = {
|
|
|
594
595
|
llm_generate_image: {
|
|
595
596
|
description: "Generate image with AI based on a text prompt",
|
|
596
597
|
requireRow: true,
|
|
597
|
-
configFields: ({ table, mode }) => {
|
|
598
|
+
configFields: async ({ table, mode }) => {
|
|
599
|
+
const roleOptions = (await User.get_roles()).map((r) => ({
|
|
600
|
+
value: r.id,
|
|
601
|
+
label: r.role,
|
|
602
|
+
}));
|
|
603
|
+
const commonFields = [
|
|
604
|
+
{
|
|
605
|
+
name: "filename",
|
|
606
|
+
label: "File name",
|
|
607
|
+
type: "String",
|
|
608
|
+
sublabel:
|
|
609
|
+
"Name of the generated file. Interpolations <code>{{ }}</code> available",
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
label: "Minimum role to access",
|
|
613
|
+
name: "min_role",
|
|
614
|
+
input_type: "select",
|
|
615
|
+
sublabel: "User must have this role or higher access image file",
|
|
616
|
+
options: roleOptions,
|
|
617
|
+
},
|
|
618
|
+
];
|
|
598
619
|
if (mode === "workflow") {
|
|
599
620
|
return [
|
|
600
621
|
{
|
|
@@ -620,6 +641,7 @@ module.exports = {
|
|
|
620
641
|
sublabel: "Override default model name",
|
|
621
642
|
type: "String",
|
|
622
643
|
},
|
|
644
|
+
...commonFields,
|
|
623
645
|
];
|
|
624
646
|
} else if (table) {
|
|
625
647
|
const textFields = table.fields
|
|
@@ -652,6 +674,7 @@ module.exports = {
|
|
|
652
674
|
required: true,
|
|
653
675
|
attributes: { options: fileFields },
|
|
654
676
|
},
|
|
677
|
+
...commonFields,
|
|
655
678
|
];
|
|
656
679
|
}
|
|
657
680
|
},
|
|
@@ -665,9 +688,9 @@ module.exports = {
|
|
|
665
688
|
prompt_formula,
|
|
666
689
|
prompt_template,
|
|
667
690
|
answer_field,
|
|
668
|
-
|
|
669
|
-
chat_history_field,
|
|
691
|
+
min_role,
|
|
670
692
|
model,
|
|
693
|
+
filename,
|
|
671
694
|
},
|
|
672
695
|
}) => {
|
|
673
696
|
let prompt;
|
|
@@ -681,6 +704,10 @@ module.exports = {
|
|
|
681
704
|
"llm_generate prompt formula"
|
|
682
705
|
);
|
|
683
706
|
else prompt = row[prompt_field];
|
|
707
|
+
|
|
708
|
+
const use_filename = filename
|
|
709
|
+
? interpolate(filename, row, user, "llm_generate_image file name")
|
|
710
|
+
: "generated.png";
|
|
684
711
|
const opts = { debugResult: true }; // response_format: "b64_json" };
|
|
685
712
|
|
|
686
713
|
if (model) opts.model = model;
|
|
@@ -697,10 +724,11 @@ module.exports = {
|
|
|
697
724
|
} else if (ans.b64_json) {
|
|
698
725
|
const imgContents = Buffer.from(ans.b64_json, "base64");
|
|
699
726
|
const file = await File.from_contents(
|
|
700
|
-
|
|
727
|
+
use_filename,
|
|
701
728
|
"image/png",
|
|
702
729
|
imgContents,
|
|
703
|
-
user?.id
|
|
730
|
+
user?.id,
|
|
731
|
+
min_role || 1
|
|
704
732
|
);
|
|
705
733
|
upd[answer_field] = file.path_to_serve;
|
|
706
734
|
}
|