@saltcorn/agents 0.2.3 → 0.3.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/common.js CHANGED
@@ -11,6 +11,7 @@ const get_skills = () => {
11
11
  require("./skills/EmbeddingRetrieval"),
12
12
  require("./skills/Trigger"),
13
13
  require("./skills/Table"),
14
+ require("./skills/PreloadData"),
14
15
  //require("./skills/AdaptiveFeedback"),
15
16
  ];
16
17
  };
@@ -44,16 +45,16 @@ const find_tool = (name, config) => {
44
45
  }
45
46
  };
46
47
 
47
- const getCompletionArguments = async (config) => {
48
+ const getCompletionArguments = async (config, user) => {
48
49
  let tools = [];
49
50
 
50
51
  let sysPrompts = [config.sys_prompt];
51
52
 
52
53
  const skills = get_skill_instances(config);
53
54
  for (const skill of skills) {
54
- const sysPr = skill.systemPrompt();
55
+ const sysPr = await skill.systemPrompt({ user });
55
56
  if (sysPr) sysPrompts.push(sysPr);
56
- const skillTools = skill.provideTools();
57
+ const skillTools = skill.provideTools?.();
57
58
  if (skillTools && Array.isArray(skillTools)) tools.push(...skillTools);
58
59
  else if (skillTools) tools.push(skillTools);
59
60
  }
@@ -129,7 +130,7 @@ const process_interaction = async (
129
130
  agent_label = "Copilot",
130
131
  prevResponses = []
131
132
  ) => {
132
- const complArgs = await getCompletionArguments(config);
133
+ const complArgs = await getCompletionArguments(config, req.user);
133
134
  complArgs.chat = run.context.interactions;
134
135
  //complArgs.debugResult = true;
135
136
  console.log("complArgs", JSON.stringify(complArgs, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/agents",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "AI agents for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -0,0 +1,92 @@
1
+ const { div, pre } = require("@saltcorn/markup/tags");
2
+ const Workflow = require("@saltcorn/data/models/workflow");
3
+ const Form = require("@saltcorn/data/models/form");
4
+ const Table = require("@saltcorn/data/models/table");
5
+ const View = require("@saltcorn/data/models/view");
6
+ const { getState } = require("@saltcorn/data/db/state");
7
+ const db = require("@saltcorn/data/db");
8
+ const { eval_expression } = require("@saltcorn/data/models/expression");
9
+ const { interpolate } = require("@saltcorn/data/utils");
10
+
11
+ class PreloadData {
12
+ static skill_name = "Preload Data";
13
+
14
+ get skill_label() {
15
+ return `Preload Data`;
16
+ }
17
+
18
+ constructor(cfg) {
19
+ Object.assign(this, cfg);
20
+ }
21
+
22
+ async systemPrompt({ user }) {
23
+ const prompts = [];
24
+ if (this.add_sys_prompt) prompts.push(this.add_sys_prompt);
25
+ const table = Table.findOne(this.table_name);
26
+ const q = eval_expression(
27
+ this.preload_query,
28
+ {},
29
+ user,
30
+ "PreloadData query"
31
+ );
32
+
33
+ const rows = await table.getRows(q);
34
+ console.log("preload data rows", rows);
35
+ if (this.contents_expr) {
36
+ for (const row of rows)
37
+ prompts.push(interpolate(this.contents_expr, row, user));
38
+ } else {
39
+ const hidden_fields = this.hidden_fields.split(",").map((s) => s.trim());
40
+ for (const row of rows) {
41
+ hidden_fields.forEach((k) => {
42
+ delete row[k];
43
+ });
44
+ prompts.push(JSON.stringify(row));
45
+ }
46
+ }
47
+ return prompts.join("\n");
48
+ }
49
+
50
+ static async configFields() {
51
+ const allTables = await Table.find();
52
+
53
+ return [
54
+ {
55
+ name: "table_name",
56
+ label: "Table",
57
+ sublabel: "Which table to search",
58
+ type: "String",
59
+ required: true,
60
+ attributes: { options: allTables.map((t) => t.name) },
61
+ },
62
+ {
63
+ name: "preload_query",
64
+ label: "Query",
65
+ type: "String",
66
+ class: "validate-expression",
67
+ },
68
+ {
69
+ name: "add_sys_prompt",
70
+ label: "Additional prompt",
71
+ type: "String",
72
+ fieldview: "textarea",
73
+ },
74
+ {
75
+ name: "contents_expr",
76
+ label: "Contents string",
77
+ type: "String",
78
+ sublabel:
79
+ "Use handlebars (<code>{{ }}</code>) to access fields in each retrieved row",
80
+ },
81
+ {
82
+ name: "hidden_fields",
83
+ label: "Hide fields",
84
+ type: "String",
85
+ sublabel:
86
+ "Comma-separated list of fields to hide from the prompt, if not using the contents string",
87
+ },
88
+ ];
89
+ }
90
+ }
91
+
92
+ module.exports = PreloadData;