llm-exe 2.1.6 → 2.1.8

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/dist/index.d.mts CHANGED
@@ -934,6 +934,12 @@ interface GeminiRequest extends GenericLLm {
934
934
  model: string;
935
935
  geminiApiKey?: string;
936
936
  }
937
+ interface DeepseekRequest extends GenericLLm {
938
+ model: string;
939
+ responseFormat?: Record<string, any>;
940
+ deepseekApiKey?: string;
941
+ useJson?: boolean;
942
+ }
937
943
  type AllEmbedding = {
938
944
  "openai.embedding.v1": {
939
945
  input: OpenAiEmbeddingOptions;
@@ -967,6 +973,9 @@ type AllLlm = {
967
973
  "google.chat.v1": {
968
974
  input: GeminiRequest;
969
975
  };
976
+ "deepseek.chat.v1": {
977
+ input: DeepseekRequest;
978
+ };
970
979
  };
971
980
  type AllUseLlmOptions = AllLlm & {
972
981
  "openai.gpt-4": {
@@ -1023,6 +1032,9 @@ type AllUseLlmOptions = AllLlm & {
1023
1032
  "ollama.qwq": {
1024
1033
  input: GenericLLm;
1025
1034
  };
1035
+ "deepseek.chat": {
1036
+ input: DeepseekRequest;
1037
+ };
1026
1038
  };
1027
1039
  type LlmProviderKey = keyof AllLlm;
1028
1040
  type EmbeddingProviderKey = keyof AllEmbedding;
@@ -1040,7 +1052,7 @@ interface BaseRequest<_T extends Record<string, any>> {
1040
1052
  interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
1041
1053
  }
1042
1054
 
1043
- type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat" | "google.chat" | "ollama.chat";
1055
+ type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat" | "google.chat" | "ollama.chat" | "deepseek.chat";
1044
1056
  interface Config<Pk = LlmProviderKey> {
1045
1057
  key: Pk;
1046
1058
  provider: LlmProvider;
@@ -1219,6 +1231,8 @@ declare namespace index {
1219
1231
  }
1220
1232
 
1221
1233
  declare const configs: {
1234
+ "deepseek.chat.v1": Config<keyof AllLlm>;
1235
+ "deepseek.chat": Config<keyof AllLlm>;
1222
1236
  "google.chat.v1": Config<keyof AllLlm>;
1223
1237
  "google.gemini-2.0-flash": Config<keyof AllLlm>;
1224
1238
  "google.gemini-2.0-flash-lite": Config<keyof AllLlm>;
package/dist/index.d.ts CHANGED
@@ -934,6 +934,12 @@ interface GeminiRequest extends GenericLLm {
934
934
  model: string;
935
935
  geminiApiKey?: string;
936
936
  }
937
+ interface DeepseekRequest extends GenericLLm {
938
+ model: string;
939
+ responseFormat?: Record<string, any>;
940
+ deepseekApiKey?: string;
941
+ useJson?: boolean;
942
+ }
937
943
  type AllEmbedding = {
938
944
  "openai.embedding.v1": {
939
945
  input: OpenAiEmbeddingOptions;
@@ -967,6 +973,9 @@ type AllLlm = {
967
973
  "google.chat.v1": {
968
974
  input: GeminiRequest;
969
975
  };
976
+ "deepseek.chat.v1": {
977
+ input: DeepseekRequest;
978
+ };
970
979
  };
971
980
  type AllUseLlmOptions = AllLlm & {
972
981
  "openai.gpt-4": {
@@ -1023,6 +1032,9 @@ type AllUseLlmOptions = AllLlm & {
1023
1032
  "ollama.qwq": {
1024
1033
  input: GenericLLm;
1025
1034
  };
1035
+ "deepseek.chat": {
1036
+ input: DeepseekRequest;
1037
+ };
1026
1038
  };
1027
1039
  type LlmProviderKey = keyof AllLlm;
1028
1040
  type EmbeddingProviderKey = keyof AllEmbedding;
@@ -1040,7 +1052,7 @@ interface BaseRequest<_T extends Record<string, any>> {
1040
1052
  interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
1041
1053
  }
1042
1054
 
1043
- type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat" | "google.chat" | "ollama.chat";
1055
+ type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat" | "google.chat" | "ollama.chat" | "deepseek.chat";
1044
1056
  interface Config<Pk = LlmProviderKey> {
1045
1057
  key: Pk;
1046
1058
  provider: LlmProvider;
@@ -1219,6 +1231,8 @@ declare namespace index {
1219
1231
  }
1220
1232
 
1221
1233
  declare const configs: {
1234
+ "deepseek.chat.v1": Config<keyof AllLlm>;
1235
+ "deepseek.chat": Config<keyof AllLlm>;
1222
1236
  "google.chat.v1": Config<keyof AllLlm>;
1223
1237
  "google.gemini-2.0-flash": Config<keyof AllLlm>;
1224
1238
  "google.gemini-2.0-flash-lite": Config<keyof AllLlm>;
package/dist/index.js CHANGED
@@ -1723,7 +1723,7 @@ var _ListToArrayParser = class _ListToArrayParser extends BaseParser {
1723
1723
  super("listToArray");
1724
1724
  }
1725
1725
  parse(text) {
1726
- const lines = text.split("\n").map((s) => s.replace("- ", "").replace(/\'/g, "'"));
1726
+ const lines = text.split("\n").map((s) => s.replace(/^- /, "").replace(/\'/g, "'").trim());
1727
1727
  return lines;
1728
1728
  }
1729
1729
  };
@@ -2236,11 +2236,27 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
2236
2236
  }
2237
2237
  if (first.role === "system" && messages.length > 0) {
2238
2238
  _outputObj.system = first.content;
2239
- return messages;
2239
+ return messages.map((m) => {
2240
+ if (m.role === "system") {
2241
+ return {
2242
+ ...m,
2243
+ role: "user"
2244
+ };
2245
+ }
2246
+ return m;
2247
+ });
2240
2248
  }
2241
2249
  return [
2242
2250
  first,
2243
- ...messages
2251
+ ...messages.map((m) => {
2252
+ if (m.role === "system") {
2253
+ return {
2254
+ ...m,
2255
+ role: "user"
2256
+ };
2257
+ }
2258
+ return m;
2259
+ })
2244
2260
  ];
2245
2261
  }
2246
2262
  __name(anthropicPromptSanitize, "anthropicPromptSanitize");
@@ -2587,6 +2603,53 @@ var google = {
2587
2603
  "google.gemini-1.5-pro": withDefaultModel(googleGeminiChatV1, "gemini-1.5-pro")
2588
2604
  };
2589
2605
 
2606
+ // src/llm/config/deepseek/index.ts
2607
+ var deepseekChatV1 = {
2608
+ key: "deepseek.chat.v1",
2609
+ provider: "deepseek.chat",
2610
+ endpoint: `https://api.deepseek.com/v1/chat/completions`,
2611
+ options: {
2612
+ prompt: {},
2613
+ topP: {},
2614
+ useJson: {},
2615
+ deepseekApiKey: {
2616
+ default: getEnvironmentVariable("DEEPSEEK_API_KEY")
2617
+ }
2618
+ },
2619
+ method: "POST",
2620
+ headers: `{"Authorization":"Bearer {{deepseekApiKey}}", "Content-Type": "application/json" }`,
2621
+ mapBody: {
2622
+ prompt: {
2623
+ key: "messages",
2624
+ sanitize: /* @__PURE__ */ __name((v) => {
2625
+ if (typeof v === "string") {
2626
+ return [
2627
+ {
2628
+ role: "user",
2629
+ content: v
2630
+ }
2631
+ ];
2632
+ }
2633
+ return v;
2634
+ }, "sanitize")
2635
+ },
2636
+ model: {
2637
+ key: "model"
2638
+ },
2639
+ topP: {
2640
+ key: "top_p"
2641
+ },
2642
+ useJson: {
2643
+ key: "response_format.type",
2644
+ sanitize: /* @__PURE__ */ __name((v) => v ? "json_object" : "text", "sanitize")
2645
+ }
2646
+ }
2647
+ };
2648
+ var deepseek = {
2649
+ "deepseek.chat.v1": deepseekChatV1,
2650
+ "deepseek.chat": withDefaultModel(deepseekChatV1, "deepseek-chat")
2651
+ };
2652
+
2590
2653
  // src/llm/config.ts
2591
2654
  var configs = {
2592
2655
  ...openai,
@@ -2594,7 +2657,8 @@ var configs = {
2594
2657
  ...bedrock,
2595
2658
  ...xai,
2596
2659
  ...ollama,
2597
- ...google
2660
+ ...google,
2661
+ ...deepseek
2598
2662
  };
2599
2663
  function getLlmConfig(provider) {
2600
2664
  if (!provider) {
@@ -3027,6 +3091,9 @@ function getOutputParser(config, response) {
3027
3091
  return OutputOllamaChat(response, config);
3028
3092
  case "google.chat.v1":
3029
3093
  return OutputGoogleGeminiChat(response, config);
3094
+ case "deepseek.chat.v1":
3095
+ return OutputOpenAIChat(response, config);
3096
+ // use oai for now
3030
3097
  default: {
3031
3098
  if (config?.key?.startsWith("custom:")) {
3032
3099
  return OutputDefault(response, config);
@@ -3037,6 +3104,42 @@ function getOutputParser(config, response) {
3037
3104
  }
3038
3105
  __name(getOutputParser, "getOutputParser");
3039
3106
 
3107
+ // src/utils/modules/debug.ts
3108
+ function debug(...args) {
3109
+ const debugValue = getEnvironmentVariable("LLM_EXE_DEBUG");
3110
+ const logs = [];
3111
+ for (const arg of args) {
3112
+ if (arg && typeof arg === "object") {
3113
+ if (arg instanceof Error) {
3114
+ } else if (arg instanceof Array) {
3115
+ logs.push(arg.map((item) => JSON.stringify(item, null, 2)));
3116
+ } else if (arg instanceof Map) {
3117
+ logs.push(Array.from(arg.entries()).map(([key, value]) => `${key}: ${JSON.stringify(value, null, 2)}`));
3118
+ } else if (arg instanceof Set) {
3119
+ logs.push(Array.from(arg).map((item) => JSON.stringify(item, null, 2)));
3120
+ } else if (arg instanceof Date) {
3121
+ logs.push(arg.toISOString());
3122
+ } else if (arg instanceof RegExp) {
3123
+ logs.push(arg.toString());
3124
+ } else {
3125
+ try {
3126
+ logs.push(JSON.stringify(arg, null, 2));
3127
+ } catch (error) {
3128
+ console.error("Error parsing object:", error);
3129
+ }
3130
+ }
3131
+ } else if (typeof arg === "string") {
3132
+ logs.push(arg);
3133
+ } else {
3134
+ logs.push(arg);
3135
+ }
3136
+ }
3137
+ if (typeof debugValue === "string" && debugValue !== "" && debugValue.toLowerCase() !== "undefined" && debugValue.toLowerCase() !== "null") {
3138
+ console.debug(...logs);
3139
+ }
3140
+ }
3141
+ __name(debug, "debug");
3142
+
3040
3143
  // src/utils/modules/isValidUrl.ts
3041
3144
  function isValidUrl(input) {
3042
3145
  try {
@@ -3054,6 +3157,7 @@ async function apiRequest(url, options) {
3054
3157
  ...options
3055
3158
  };
3056
3159
  try {
3160
+ debug(url, finalOptions);
3057
3161
  if (!url || !isValidUrl(url)) {
3058
3162
  throw new Error("Invalid URL");
3059
3163
  }
package/dist/index.mjs CHANGED
@@ -1675,7 +1675,7 @@ var _ListToArrayParser = class _ListToArrayParser extends BaseParser {
1675
1675
  super("listToArray");
1676
1676
  }
1677
1677
  parse(text) {
1678
- const lines = text.split("\n").map((s) => s.replace("- ", "").replace(/\'/g, "'"));
1678
+ const lines = text.split("\n").map((s) => s.replace(/^- /, "").replace(/\'/g, "'").trim());
1679
1679
  return lines;
1680
1680
  }
1681
1681
  };
@@ -2188,11 +2188,27 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
2188
2188
  }
2189
2189
  if (first.role === "system" && messages.length > 0) {
2190
2190
  _outputObj.system = first.content;
2191
- return messages;
2191
+ return messages.map((m) => {
2192
+ if (m.role === "system") {
2193
+ return {
2194
+ ...m,
2195
+ role: "user"
2196
+ };
2197
+ }
2198
+ return m;
2199
+ });
2192
2200
  }
2193
2201
  return [
2194
2202
  first,
2195
- ...messages
2203
+ ...messages.map((m) => {
2204
+ if (m.role === "system") {
2205
+ return {
2206
+ ...m,
2207
+ role: "user"
2208
+ };
2209
+ }
2210
+ return m;
2211
+ })
2196
2212
  ];
2197
2213
  }
2198
2214
  __name(anthropicPromptSanitize, "anthropicPromptSanitize");
@@ -2539,6 +2555,53 @@ var google = {
2539
2555
  "google.gemini-1.5-pro": withDefaultModel(googleGeminiChatV1, "gemini-1.5-pro")
2540
2556
  };
2541
2557
 
2558
+ // src/llm/config/deepseek/index.ts
2559
+ var deepseekChatV1 = {
2560
+ key: "deepseek.chat.v1",
2561
+ provider: "deepseek.chat",
2562
+ endpoint: `https://api.deepseek.com/v1/chat/completions`,
2563
+ options: {
2564
+ prompt: {},
2565
+ topP: {},
2566
+ useJson: {},
2567
+ deepseekApiKey: {
2568
+ default: getEnvironmentVariable("DEEPSEEK_API_KEY")
2569
+ }
2570
+ },
2571
+ method: "POST",
2572
+ headers: `{"Authorization":"Bearer {{deepseekApiKey}}", "Content-Type": "application/json" }`,
2573
+ mapBody: {
2574
+ prompt: {
2575
+ key: "messages",
2576
+ sanitize: /* @__PURE__ */ __name((v) => {
2577
+ if (typeof v === "string") {
2578
+ return [
2579
+ {
2580
+ role: "user",
2581
+ content: v
2582
+ }
2583
+ ];
2584
+ }
2585
+ return v;
2586
+ }, "sanitize")
2587
+ },
2588
+ model: {
2589
+ key: "model"
2590
+ },
2591
+ topP: {
2592
+ key: "top_p"
2593
+ },
2594
+ useJson: {
2595
+ key: "response_format.type",
2596
+ sanitize: /* @__PURE__ */ __name((v) => v ? "json_object" : "text", "sanitize")
2597
+ }
2598
+ }
2599
+ };
2600
+ var deepseek = {
2601
+ "deepseek.chat.v1": deepseekChatV1,
2602
+ "deepseek.chat": withDefaultModel(deepseekChatV1, "deepseek-chat")
2603
+ };
2604
+
2542
2605
  // src/llm/config.ts
2543
2606
  var configs = {
2544
2607
  ...openai,
@@ -2546,7 +2609,8 @@ var configs = {
2546
2609
  ...bedrock,
2547
2610
  ...xai,
2548
2611
  ...ollama,
2549
- ...google
2612
+ ...google,
2613
+ ...deepseek
2550
2614
  };
2551
2615
  function getLlmConfig(provider) {
2552
2616
  if (!provider) {
@@ -2979,6 +3043,9 @@ function getOutputParser(config, response) {
2979
3043
  return OutputOllamaChat(response, config);
2980
3044
  case "google.chat.v1":
2981
3045
  return OutputGoogleGeminiChat(response, config);
3046
+ case "deepseek.chat.v1":
3047
+ return OutputOpenAIChat(response, config);
3048
+ // use oai for now
2982
3049
  default: {
2983
3050
  if (config?.key?.startsWith("custom:")) {
2984
3051
  return OutputDefault(response, config);
@@ -2989,6 +3056,42 @@ function getOutputParser(config, response) {
2989
3056
  }
2990
3057
  __name(getOutputParser, "getOutputParser");
2991
3058
 
3059
+ // src/utils/modules/debug.ts
3060
+ function debug(...args) {
3061
+ const debugValue = getEnvironmentVariable("LLM_EXE_DEBUG");
3062
+ const logs = [];
3063
+ for (const arg of args) {
3064
+ if (arg && typeof arg === "object") {
3065
+ if (arg instanceof Error) {
3066
+ } else if (arg instanceof Array) {
3067
+ logs.push(arg.map((item) => JSON.stringify(item, null, 2)));
3068
+ } else if (arg instanceof Map) {
3069
+ logs.push(Array.from(arg.entries()).map(([key, value]) => `${key}: ${JSON.stringify(value, null, 2)}`));
3070
+ } else if (arg instanceof Set) {
3071
+ logs.push(Array.from(arg).map((item) => JSON.stringify(item, null, 2)));
3072
+ } else if (arg instanceof Date) {
3073
+ logs.push(arg.toISOString());
3074
+ } else if (arg instanceof RegExp) {
3075
+ logs.push(arg.toString());
3076
+ } else {
3077
+ try {
3078
+ logs.push(JSON.stringify(arg, null, 2));
3079
+ } catch (error) {
3080
+ console.error("Error parsing object:", error);
3081
+ }
3082
+ }
3083
+ } else if (typeof arg === "string") {
3084
+ logs.push(arg);
3085
+ } else {
3086
+ logs.push(arg);
3087
+ }
3088
+ }
3089
+ if (typeof debugValue === "string" && debugValue !== "" && debugValue.toLowerCase() !== "undefined" && debugValue.toLowerCase() !== "null") {
3090
+ console.debug(...logs);
3091
+ }
3092
+ }
3093
+ __name(debug, "debug");
3094
+
2992
3095
  // src/utils/modules/isValidUrl.ts
2993
3096
  function isValidUrl(input) {
2994
3097
  try {
@@ -3006,6 +3109,7 @@ async function apiRequest(url, options) {
3006
3109
  ...options
3007
3110
  };
3008
3111
  try {
3112
+ debug(url, finalOptions);
3009
3113
  if (!url || !isValidUrl(url)) {
3010
3114
  throw new Error("Invalid URL");
3011
3115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llm-exe",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "description": "Simplify building LLM-powered apps with easy-to-use base components, supporting text and chat-based prompts with handlebars template engine, output parsers, and flexible function calling capabilities.",
5
5
  "keywords": [
6
6
  "ai",
package/readme.md CHANGED
@@ -7,7 +7,7 @@ A package that provides simplified base components to make building and maintain
7
7
  - Write functions powered by LLM's with easy to use building blocks.
8
8
  - Pure Javascript and Typescript. Allows you to pass and infer types.
9
9
  - Support for text-based (llama-3) and chat-based prompts. (gpt-4o, claude-3.5, grok-3, Gemini, Bedrock, Ollama, etc)
10
- - Call LLM's from different providers without changing your code. (OpenAi/Anthropic/xAI/Google/AWS Bedrock/Ollama)
10
+ - Call LLM's from different providers without changing your code. (OpenAi/Anthropic/xAI/Google/AWS Bedrock/Ollama/Deepseek)
11
11
  - Supercharge your prompts by using handlebars within prompt template.
12
12
  - Allow LLM's to call functions (or call other LLM executors).
13
13
  - Not very opinionated. You have control on how you use it.
@@ -52,7 +52,7 @@ export async function YesOrNoBot<I extends string>(input: I) {
52
52
  const prompt = llmExe
53
53
  .createChatPrompt(instruction)
54
54
  .addUserMessage(input)
55
- .addSystemMessage(`yes or no:`);
55
+ .addUserMessage(`yes or no:`);
56
56
 
57
57
  const parser = llmExe.createParser("stringExtract", { enum: ["yes", "no"] });
58
58
  return llmExe.createLlmExecutor({ llm, prompt, parser }).execute({ input });