@saltcorn/large-language-model 0.9.5 → 0.9.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.
Files changed (3) hide show
  1. package/generate.js +6 -6
  2. package/index.js +27 -5
  3. package/package.json +1 -1
package/generate.js CHANGED
@@ -213,6 +213,7 @@ const getCompletionAISDK = async (
213
213
  }
214
214
 
215
215
  const body = {
216
+ ...rest,
216
217
  model: model_obj,
217
218
  messages: [
218
219
  {
@@ -222,7 +223,6 @@ const getCompletionAISDK = async (
222
223
  ...chat,
223
224
  ...(prompt ? [{ role: "user", content: prompt }] : []),
224
225
  ],
225
- ...rest,
226
226
  };
227
227
  if (rest.temperature || temperature) {
228
228
  const str_or_num = rest.temperature || temperature;
@@ -257,7 +257,7 @@ const getCompletionAISDK = async (
257
257
  const debugRequest = { ...body, model: use_model_name };
258
258
  if (debugResult)
259
259
  console.log("AI SDK request", JSON.stringify(debugRequest, null, 2));
260
- getState().log(6, `OpenAI request ${JSON.stringify(debugRequest)} `);
260
+ getState().log(6, `AI SDK request ${JSON.stringify(debugRequest)} `);
261
261
  if (debugCollector) debugCollector.request = debugRequest;
262
262
  const reqTimeStart = Date.now();
263
263
 
@@ -270,8 +270,8 @@ const getCompletionAISDK = async (
270
270
  }
271
271
  } else results = await generateText(body);
272
272
  if (debugResult)
273
- console.log("OpenAI response", JSON.stringify(results, null, 2));
274
- else getState().log(6, `OpenAI response ${JSON.stringify(results)}`);
273
+ console.log("AI SDK response", JSON.stringify(results, null, 2));
274
+ else getState().log(6, `AI SDK response ${JSON.stringify(results)}`);
275
275
  if (debugCollector) {
276
276
  debugCollector.response = results;
277
277
  debugCollector.response_time_ms = Date.now() - reqTimeStart;
@@ -669,11 +669,11 @@ const getEmbeddingAISDK = async (config, { prompt, model, debugResult }) => {
669
669
  providerOptions,
670
670
  };
671
671
  if (Array.isArray(prompt)) {
672
- body.values = prompt
672
+ body.values = prompt;
673
673
  const { embeddings } = await embedMany(body);
674
674
  return embeddings;
675
675
  } else {
676
- body.value = prompt
676
+ body.value = prompt;
677
677
  const { embedding } = await embed(body);
678
678
  return embedding;
679
679
  }
package/index.js CHANGED
@@ -809,6 +809,7 @@ module.exports = {
809
809
  {
810
810
  name: "name",
811
811
  label: "Name",
812
+ class: "validate-identifier",
812
813
  sublabel: "The field name, as a valid JavaScript identifier",
813
814
  type: "String",
814
815
  required: true,
@@ -828,6 +829,13 @@ module.exports = {
828
829
  options: ["string", "integer", "number", "boolean"],
829
830
  },
830
831
  },
832
+ {
833
+ name: "options",
834
+ label: "Options",
835
+ type: "String",
836
+ sublabel: "Optional. Comma-separated list of values",
837
+ showIf: { type: "string" },
838
+ },
831
839
  ],
832
840
  });
833
841
 
@@ -898,6 +906,12 @@ module.exports = {
898
906
  sublabel: "A short description of what you want to generate.",
899
907
  type: "String",
900
908
  },
909
+ {
910
+ name: "model",
911
+ label: "Model",
912
+ sublabel: "Override default model name",
913
+ type: "String",
914
+ },
901
915
  {
902
916
  input_type: "section_header",
903
917
  label: "JSON fields to generate",
@@ -914,16 +928,18 @@ module.exports = {
914
928
  configuration: {
915
929
  prompt_template,
916
930
  fields,
917
- mulitple,
931
+ multiple,
918
932
  gen_description,
919
933
  answer_field,
920
934
  override_config,
921
935
  chat_history_field,
936
+ model,
922
937
  },
923
938
  }) => {
924
939
  let prompt = interpolate(prompt_template, row, user);
925
940
 
926
941
  const opts = {};
942
+ if (model) opts.model = model;
927
943
  if (override_config) {
928
944
  const altcfg = config.altconfigs.find(
929
945
  (c) => c.name === override_config
@@ -943,10 +959,14 @@ module.exports = {
943
959
  type: field.type,
944
960
  description: field.description,
945
961
  };
962
+ if (field.type === "string" && field.options)
963
+ fieldArgs[field.name].enum = field.options
964
+ .split(",")
965
+ .map((s) => s.trim());
946
966
  });
947
967
  const argObj = { type: "object", properties: fieldArgs };
948
968
  const args = {
949
- [answer_field]: mulitple ? { type: "array", items: argObj } : argObj,
969
+ [answer_field]: multiple ? { type: "array", items: argObj } : argObj,
950
970
  };
951
971
  const expert_function = {
952
972
  type: "function",
@@ -969,9 +989,11 @@ module.exports = {
969
989
  ...opts,
970
990
  ...toolargs,
971
991
  });
972
- const ans = JSON.parse(compl.tool_calls[0].function.arguments)[
973
- answer_field
974
- ];
992
+ console.log(JSON.stringify(compl, null, 2));
993
+
994
+ const ans = compl.tool_calls[0].input
995
+ ? compl.tool_calls[0].input[answer_field]
996
+ : JSON.parse(compl.tool_calls[0].function.arguments)[answer_field];
975
997
  const upd = { [answer_field]: ans };
976
998
  if (chat_history_field) {
977
999
  upd[chat_history_field] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/large-language-model",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "description": "Large language models and functionality for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {