@saltcorn/large-language-model 1.0.9 → 1.0.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.
Files changed (3) hide show
  1. package/generate.js +38 -7
  2. package/index.js +1 -0
  3. package/package.json +1 -1
package/generate.js CHANGED
@@ -553,7 +553,12 @@ const getCompletionAISDK = async (
553
553
  const debugRequest = { ...body, model: use_model_name };
554
554
  if (debugResult)
555
555
  console.log("AI SDK request", JSON.stringify(debugRequest, null, 2));
556
- getState().log(6, `AI SDK request ${JSON.stringify(debugRequest)} `);
556
+ getState().log(
557
+ 6,
558
+ `AI SDK request`,
559
+ { tools: Object.keys(debugRequest.tools || {}), model: debugRequest.model },
560
+ JSON.stringify(debugRequest.messages, null, 2),
561
+ );
557
562
  if (debugCollector) debugCollector.request = debugRequest;
558
563
  const reqTimeStart = Date.now();
559
564
 
@@ -575,15 +580,18 @@ const getCompletionAISDK = async (
575
580
  chat.push(...results.response.messages);
576
581
  }
577
582
 
578
- if (debugResult)
579
- console.log("AI SDK response", JSON.stringify(results, null, 2));
580
- else getState().log(6, `AI SDK response ${JSON.stringify(results)}`);
581
583
  if (debugCollector) {
582
584
  debugCollector.response = results;
583
585
  debugCollector.response_time_ms = Date.now() - reqTimeStart;
584
586
  }
585
587
  const allToolCalls = (await results.steps).flatMap((step) => step.toolCalls);
586
-
588
+ if (debugResult)
589
+ console.log("AI SDK response", JSON.stringify(results, null, 2));
590
+ else
591
+ getState().log(6, `AI SDK response`, {
592
+ text: results.text,
593
+ tool_calls: allToolCalls,
594
+ });
587
595
  if (allToolCalls.length) {
588
596
  return {
589
597
  tool_calls: allToolCalls,
@@ -838,10 +846,29 @@ const getCompletionOpenAICompatible = async (
838
846
  if (streamToolCalls) debugCollector.response = streamToolCalls;
839
847
  debugCollector.response_time_ms = Date.now() - reqTimeStart;
840
848
  }
849
+ if (appendToChat && chat && streamToolCalls) {
850
+ chat.push({
851
+ role: "assistant",
852
+ content: streamParts.join("") || null,
853
+ tool_calls: streamToolCalls.tool_calls,
854
+ });
855
+ } else if (appendToChat && chat && streamParts.length > 0) {
856
+ chat.push({ role: "assistant", content: streamParts.join("") });
857
+ }
841
858
  return streamToolCalls
842
859
  ? {
843
860
  content: streamParts.join(""),
844
861
  tool_calls: streamToolCalls.tool_calls,
862
+ hasToolCalls: streamToolCalls.tool_calls?.length,
863
+ getToolCalls() {
864
+ return streamToolCalls.tool_calls.map((tc) => ({
865
+ tool_name: tc.function.name,
866
+ input: tc.function.arguments
867
+ ? JSON.parse(tc.function.arguments)
868
+ : {},
869
+ tool_call_id: tc.id,
870
+ }));
871
+ },
845
872
  }
846
873
  : streamParts.join("");
847
874
  }
@@ -895,7 +922,9 @@ const getCompletionOpenAICompatible = async (
895
922
  getToolCalls() {
896
923
  return tool_calls.map((tc) => ({
897
924
  tool_name: tc.function.name,
898
- input: JSON.parse(tc.function.arguments),
925
+ input: tc.function.arguments
926
+ ? JSON.parse(tc.function.arguments)
927
+ : {},
899
928
  tool_call_id: tc.call_id,
900
929
  }));
901
930
  },
@@ -910,7 +939,9 @@ const getCompletionOpenAICompatible = async (
910
939
  getToolCalls() {
911
940
  return results?.choices?.[0]?.message?.tool_calls.map((tc) => ({
912
941
  tool_name: tc.function.name,
913
- input: JSON.parse(tc.function.arguments),
942
+ input: tc.function.arguments
943
+ ? JSON.parse(tc.function.arguments)
944
+ : {},
914
945
  tool_call_id: tc.id,
915
946
  }));
916
947
  },
package/index.js CHANGED
@@ -658,6 +658,7 @@ module.exports = {
658
658
  functions,
659
659
  modelpatterns: require("./model.js"),
660
660
  routes,
661
+ ready_for_mobile: false,
661
662
  actions: (config) => ({
662
663
  llm_function_call: require("./function-insert-action.js")(config),
663
664
  llm_generate: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/large-language-model",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Large language models and functionality for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {