@saltcorn/large-language-model 0.6.3 → 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.
Files changed (2) hide show
  1. package/index.js +27 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -227,6 +227,13 @@ module.exports = {
227
227
  type: "String",
228
228
  required: true,
229
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
+ },
230
237
  ...override_fields,
231
238
  ];
232
239
  }
@@ -273,6 +280,7 @@ module.exports = {
273
280
  prompt_template,
274
281
  answer_field,
275
282
  override_config,
283
+ chat_history_field,
276
284
  },
277
285
  }) => {
278
286
  let prompt;
@@ -296,9 +304,25 @@ module.exports = {
296
304
  opts.api_key = altcfg.api_key;
297
305
  opts.bearer = altcfg.bearer;
298
306
  }
299
- const ans = await getCompletion(config, { prompt, ...opts });
300
- if (mode === "workflow") return { [answer_field]: ans };
301
- else await table.updateRow({ [answer_field]: ans }, row[table.pk_name]);
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]);
302
326
  },
303
327
  },
304
328
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/large-language-model",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Large language models and functionality for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {