@saltcorn/large-language-model 0.7.9 → 0.7.10

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.
@@ -11,7 +11,7 @@ const { eval_expression } = require("@saltcorn/data/models/expression");
11
11
  const noSpaces = (s) => s.replaceAll(" ", "");
12
12
  module.exports = (config) => ({
13
13
  description: "Use LLM function call to insert rows in tables",
14
- requireRow: true,
14
+ //requireRow: true,
15
15
  disableInList: true,
16
16
  disableInBuilder: true,
17
17
  configFields: async ({ table }) => {
@@ -22,7 +22,9 @@ module.exports = (config) => ({
22
22
  label: "Prompt",
23
23
  type: "String",
24
24
  fieldview: "textarea",
25
- sublabel: `Use interpolations {{ }} to access variables in ${table.name} table.`,
25
+ sublabel: table
26
+ ? `Use interpolations {{ }} to access variables in ${table.name} table.`
27
+ : undefined,
26
28
  },
27
29
  {
28
30
  name: "function_name",
@@ -55,6 +57,7 @@ module.exports = (config) => ({
55
57
  name: "cardinality",
56
58
  label: "Cardinality",
57
59
  type: "String",
60
+ sublabel: "How many rows to generate",
58
61
  required: true,
59
62
  attributes: {
60
63
  options: ["One", /*"Zero or one",*/ "Zero to many"],
@@ -78,6 +81,9 @@ module.exports = (config) => ({
78
81
  const prompt = interpolate(prompt_template, row, user);
79
82
  let args = {};
80
83
  const json_type = (ty) => {
84
+ if (ty?.name === "Date") return "string";
85
+ //console.log("getting type of ", ty);
86
+
81
87
  if (ty?.js_type) return ty?.js_type;
82
88
  };
83
89
 
@@ -95,7 +101,7 @@ module.exports = (config) => ({
95
101
  if (typeof fixed[field.name] !== "undefined") continue;
96
102
  tableArgs[field.name] = {
97
103
  type: json_type(field.type),
98
- description: field.description,
104
+ description: field.description || field.label,
99
105
  };
100
106
  }
101
107
  const argObj = { type: "object", properties: tableArgs };
@@ -116,6 +122,7 @@ module.exports = (config) => ({
116
122
  },
117
123
  },
118
124
  };
125
+
119
126
  const toolargs = {
120
127
  tools: [expert_function],
121
128
  tool_choice: { type: "function", function: { name: function_name } },
@@ -125,10 +132,11 @@ module.exports = (config) => ({
125
132
  getState().log(6, `llm_function_call completion: ${JSON.stringify(compl)}`);
126
133
  const response = JSON.parse(compl.tool_calls[0].function.arguments);
127
134
  //console.log("response: ", JSON.stringify(response, null, 2));
135
+ const retval = {};
128
136
  for (const col of columns) {
129
137
  const target_table = Table.findOne({ name: col.target_table });
130
138
  const fixed = eval_expression(
131
- col.fixed_values,
139
+ col.fixed_values || {},
132
140
  row,
133
141
  user,
134
142
  "llm_function_call fixed values"
@@ -139,14 +147,17 @@ module.exports = (config) => ({
139
147
  ...(response[noSpaces(target_table.name)] || {}),
140
148
  ...fixed,
141
149
  };
150
+ retval[noSpaces(target_table.name)] = row;
142
151
  await target_table.insertRow(row, user);
143
152
  } else {
153
+ retval[noSpaces(target_table.name)] = [];
144
154
  for (const resp of response[noSpaces(target_table.name)] || []) {
145
155
  const row = { ...resp, ...fixed };
156
+ retval[noSpaces(target_table.name)].push(row);
146
157
  await target_table.insertRow(row, user);
147
158
  }
148
159
  }
149
160
  }
150
- return {};
161
+ return retval;
151
162
  },
152
163
  });
package/index.js CHANGED
@@ -69,9 +69,9 @@ ${domReady(`
69
69
  name: "ollama_host",
70
70
  label: "Host",
71
71
  sublabel: "Optional, for remote ollama server",
72
- type: "String",
72
+ type: "String",
73
73
  showIf: { backend: "Local Ollama" },
74
- },
74
+ },
75
75
  {
76
76
  name: "client_id",
77
77
  label: "Client ID",
@@ -462,6 +462,12 @@ module.exports = {
462
462
  type: "String",
463
463
  },
464
464
  ...override_fields,
465
+ {
466
+ name: "model",
467
+ label: "Model",
468
+ sublabel: "Override default model name",
469
+ type: "String",
470
+ },
465
471
  ];
466
472
  } else if (table) {
467
473
  const textFields = table.fields
@@ -507,6 +513,7 @@ module.exports = {
507
513
  answer_field,
508
514
  override_config,
509
515
  chat_history_field,
516
+ model,
510
517
  },
511
518
  }) => {
512
519
  let prompt;
@@ -530,6 +537,7 @@ module.exports = {
530
537
  opts.api_key = altcfg.api_key;
531
538
  opts.bearer = altcfg.bearer;
532
539
  }
540
+ if (model) opts.model = model;
533
541
  let history = [];
534
542
  if (chat_history_field && row[chat_history_field]) {
535
543
  history = row[chat_history_field];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/large-language-model",
3
- "version": "0.7.9",
3
+ "version": "0.7.10",
4
4
  "description": "Large language models and functionality for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {