llm-exe 0.0.1

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 (185) hide show
  1. package/dist/embedding/base.d.ts +8 -0
  2. package/dist/embedding/base.js +43 -0
  3. package/dist/embedding/base.js.map +1 -0
  4. package/dist/embedding/openai.d.ts +11 -0
  5. package/dist/embedding/openai.js +72 -0
  6. package/dist/embedding/openai.js.map +1 -0
  7. package/dist/executor/_base.d.ts +54 -0
  8. package/dist/executor/_base.js +173 -0
  9. package/dist/executor/_base.js.map +1 -0
  10. package/dist/executor/_functions.d.ts +25 -0
  11. package/dist/executor/_functions.js +30 -0
  12. package/dist/executor/_functions.js.map +1 -0
  13. package/dist/executor/_metadata.d.ts +8 -0
  14. package/dist/executor/_metadata.js +69 -0
  15. package/dist/executor/_metadata.js.map +1 -0
  16. package/dist/executor/core.d.ts +10 -0
  17. package/dist/executor/core.js +28 -0
  18. package/dist/executor/core.js.map +1 -0
  19. package/dist/executor/index.d.ts +4 -0
  20. package/dist/executor/index.js +13 -0
  21. package/dist/executor/index.js.map +1 -0
  22. package/dist/executor/llm.d.ts +29 -0
  23. package/dist/executor/llm.js +73 -0
  24. package/dist/executor/llm.js.map +1 -0
  25. package/dist/index.d.ts +61 -0
  26. package/dist/index.js +88 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/interfaces/chat.d.ts +19 -0
  29. package/dist/interfaces/chat.js +3 -0
  30. package/dist/interfaces/chat.js.map +1 -0
  31. package/dist/interfaces/functions.d.ts +72 -0
  32. package/dist/interfaces/functions.js +3 -0
  33. package/dist/interfaces/functions.js.map +1 -0
  34. package/dist/interfaces/index.d.ts +6 -0
  35. package/dist/interfaces/index.js +23 -0
  36. package/dist/interfaces/index.js.map +1 -0
  37. package/dist/interfaces/openai.d.ts +33 -0
  38. package/dist/interfaces/openai.js +3 -0
  39. package/dist/interfaces/openai.js.map +1 -0
  40. package/dist/interfaces/parser.d.ts +11 -0
  41. package/dist/interfaces/parser.js +3 -0
  42. package/dist/interfaces/parser.js.map +1 -0
  43. package/dist/interfaces/prompt.d.ts +20 -0
  44. package/dist/interfaces/prompt.js +3 -0
  45. package/dist/interfaces/prompt.js.map +1 -0
  46. package/dist/interfaces/utils.d.ts +15 -0
  47. package/dist/interfaces/utils.js +3 -0
  48. package/dist/interfaces/utils.js.map +1 -0
  49. package/dist/llm/_base.d.ts +78 -0
  50. package/dist/llm/_base.js +164 -0
  51. package/dist/llm/_base.js.map +1 -0
  52. package/dist/llm/index.d.ts +2 -0
  53. package/dist/llm/index.js +9 -0
  54. package/dist/llm/index.js.map +1 -0
  55. package/dist/llm/openai.d.ts +95 -0
  56. package/dist/llm/openai.js +274 -0
  57. package/dist/llm/openai.js.map +1 -0
  58. package/dist/llm/output/base.d.ts +12 -0
  59. package/dist/llm/output/base.js +45 -0
  60. package/dist/llm/output/base.js.map +1 -0
  61. package/dist/llm/output/index.d.ts +9 -0
  62. package/dist/llm/output/index.js +29 -0
  63. package/dist/llm/output/index.js.map +1 -0
  64. package/dist/llm/output/openai-chat.d.ts +13 -0
  65. package/dist/llm/output/openai-chat.js +51 -0
  66. package/dist/llm/output/openai-chat.js.map +1 -0
  67. package/dist/parser/_base.d.ts +33 -0
  68. package/dist/parser/_base.js +64 -0
  69. package/dist/parser/_base.js.map +1 -0
  70. package/dist/parser/_functions.d.ts +94 -0
  71. package/dist/parser/_functions.js +52 -0
  72. package/dist/parser/_functions.js.map +1 -0
  73. package/dist/parser/index.d.ts +14 -0
  74. package/dist/parser/index.js +31 -0
  75. package/dist/parser/index.js.map +1 -0
  76. package/dist/parser/parsers/BooleanParser.d.ts +8 -0
  77. package/dist/parser/parsers/BooleanParser.js +20 -0
  78. package/dist/parser/parsers/BooleanParser.js.map +1 -0
  79. package/dist/parser/parsers/CustomParser.d.ts +27 -0
  80. package/dist/parser/parsers/CustomParser.js +41 -0
  81. package/dist/parser/parsers/CustomParser.js.map +1 -0
  82. package/dist/parser/parsers/JsonParser.d.ts +7 -0
  83. package/dist/parser/parsers/JsonParser.js +15 -0
  84. package/dist/parser/parsers/JsonParser.js.map +1 -0
  85. package/dist/parser/parsers/ListToArrayParser.d.ts +5 -0
  86. package/dist/parser/parsers/ListToArrayParser.js +17 -0
  87. package/dist/parser/parsers/ListToArrayParser.js.map +1 -0
  88. package/dist/parser/parsers/ListToJsonParser.d.ts +7 -0
  89. package/dist/parser/parsers/ListToJsonParser.js +25 -0
  90. package/dist/parser/parsers/ListToJsonParser.js.map +1 -0
  91. package/dist/parser/parsers/ListToKeyValueParser.d.ts +14 -0
  92. package/dist/parser/parsers/ListToKeyValueParser.js +24 -0
  93. package/dist/parser/parsers/ListToKeyValueParser.js.map +1 -0
  94. package/dist/parser/parsers/MarkdownCodeBlock.d.ts +14 -0
  95. package/dist/parser/parsers/MarkdownCodeBlock.js +16 -0
  96. package/dist/parser/parsers/MarkdownCodeBlock.js.map +1 -0
  97. package/dist/parser/parsers/MarkdownCodeBlocks.d.ts +14 -0
  98. package/dist/parser/parsers/MarkdownCodeBlocks.js +25 -0
  99. package/dist/parser/parsers/MarkdownCodeBlocks.js.map +1 -0
  100. package/dist/parser/parsers/NumberParser.d.ts +8 -0
  101. package/dist/parser/parsers/NumberParser.js +16 -0
  102. package/dist/parser/parsers/NumberParser.js.map +1 -0
  103. package/dist/parser/parsers/ReplaceStringTemplateParser.d.ts +8 -0
  104. package/dist/parser/parsers/ReplaceStringTemplateParser.js +15 -0
  105. package/dist/parser/parsers/ReplaceStringTemplateParser.js.map +1 -0
  106. package/dist/parser/parsers/StringParser.d.ts +8 -0
  107. package/dist/parser/parsers/StringParser.js +17 -0
  108. package/dist/parser/parsers/StringParser.js.map +1 -0
  109. package/dist/plugins/callable/callable.d.ts +72 -0
  110. package/dist/plugins/callable/callable.js +107 -0
  111. package/dist/plugins/callable/callable.js.map +1 -0
  112. package/dist/plugins/callable/index.d.ts +26 -0
  113. package/dist/plugins/callable/index.js +28 -0
  114. package/dist/plugins/callable/index.js.map +1 -0
  115. package/dist/prompt/_base.d.ts +56 -0
  116. package/dist/prompt/_base.js +139 -0
  117. package/dist/prompt/_base.js.map +1 -0
  118. package/dist/prompt/_functions.d.ts +19 -0
  119. package/dist/prompt/_functions.js +24 -0
  120. package/dist/prompt/_functions.js.map +1 -0
  121. package/dist/prompt/chat.d.ts +68 -0
  122. package/dist/prompt/chat.js +136 -0
  123. package/dist/prompt/chat.js.map +1 -0
  124. package/dist/prompt/index.d.ts +4 -0
  125. package/dist/prompt/index.js +13 -0
  126. package/dist/prompt/index.js.map +1 -0
  127. package/dist/prompt/text.d.ts +9 -0
  128. package/dist/prompt/text.js +16 -0
  129. package/dist/prompt/text.js.map +1 -0
  130. package/dist/state/_base.d.ts +29 -0
  131. package/dist/state/_base.js +92 -0
  132. package/dist/state/_base.js.map +1 -0
  133. package/dist/state/_functions.d.ts +6 -0
  134. package/dist/state/_functions.js +19 -0
  135. package/dist/state/_functions.js.map +1 -0
  136. package/dist/state/dialogue.d.ts +17 -0
  137. package/dist/state/dialogue.js +66 -0
  138. package/dist/state/dialogue.js.map +1 -0
  139. package/dist/state/index.d.ts +4 -0
  140. package/dist/state/index.js +16 -0
  141. package/dist/state/index.js.map +1 -0
  142. package/dist/state/item.d.ts +23 -0
  143. package/dist/state/item.js +64 -0
  144. package/dist/state/item.js.map +1 -0
  145. package/dist/types/index.d.ts +1 -0
  146. package/dist/types/index.js +18 -0
  147. package/dist/types/index.js.map +1 -0
  148. package/dist/utils/index.d.ts +1 -0
  149. package/dist/utils/index.js +18 -0
  150. package/dist/utils/index.js.map +1 -0
  151. package/dist/utils/modules/asyncCallWithTimeout.d.ts +1 -0
  152. package/dist/utils/modules/asyncCallWithTimeout.js +17 -0
  153. package/dist/utils/modules/asyncCallWithTimeout.js.map +1 -0
  154. package/dist/utils/modules/handlebars/helpers/index.d.ts +7 -0
  155. package/dist/utils/modules/handlebars/helpers/index.js +71 -0
  156. package/dist/utils/modules/handlebars/helpers/index.js.map +1 -0
  157. package/dist/utils/modules/handlebars/index.d.ts +2 -0
  158. package/dist/utils/modules/handlebars/index.js +105 -0
  159. package/dist/utils/modules/handlebars/index.js.map +1 -0
  160. package/dist/utils/modules/handlebars/templates/index.d.ts +9 -0
  161. package/dist/utils/modules/handlebars/templates/index.js +34 -0
  162. package/dist/utils/modules/handlebars/templates/index.js.map +1 -0
  163. package/dist/utils/modules/index.d.ts +42 -0
  164. package/dist/utils/modules/index.js +133 -0
  165. package/dist/utils/modules/index.js.map +1 -0
  166. package/dist/utils/modules/json-schema-filter.d.ts +1 -0
  167. package/dist/utils/modules/json-schema-filter.js +69 -0
  168. package/dist/utils/modules/json-schema-filter.js.map +1 -0
  169. package/dist/utils/modules/json.d.ts +3 -0
  170. package/dist/utils/modules/json.js +57 -0
  171. package/dist/utils/modules/json.js.map +1 -0
  172. package/dist/utils/modules/replaceTemplateString.d.ts +2 -0
  173. package/dist/utils/modules/replaceTemplateString.js +21 -0
  174. package/dist/utils/modules/replaceTemplateString.js.map +1 -0
  175. package/dist/vector/base.d.ts +11 -0
  176. package/dist/vector/base.js +23 -0
  177. package/dist/vector/base.js.map +1 -0
  178. package/dist/vector/index.d.ts +2 -0
  179. package/dist/vector/index.js +8 -0
  180. package/dist/vector/index.js.map +1 -0
  181. package/dist/vector/pinecone.d.ts +6 -0
  182. package/dist/vector/pinecone.js +22 -0
  183. package/dist/vector/pinecone.js.map +1 -0
  184. package/package.json +67 -0
  185. package/readme.md +12 -0
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LlmExecutor = void 0;
4
+ const parser_1 = require("../parser");
5
+ const _base_1 = require("./_base");
6
+ /**
7
+ * Core Executor With LLM
8
+ */
9
+ class LlmExecutor extends _base_1.BaseExecutor {
10
+ constructor(llmConfiguration, options) {
11
+ super(llmConfiguration.name || "anonymous-llm-executor", "llm-executor", options);
12
+ Object.defineProperty(this, "llm", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "prompt", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "promptFn", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "parser", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ this.llm = llmConfiguration.llm;
37
+ this.parser = llmConfiguration?.parser || new parser_1.StringParser();
38
+ if (typeof llmConfiguration.prompt === "function") {
39
+ this.prompt = undefined;
40
+ this.promptFn = llmConfiguration.prompt;
41
+ }
42
+ else {
43
+ this.prompt = llmConfiguration.prompt;
44
+ this.promptFn = null;
45
+ }
46
+ }
47
+ async handler(_input) {
48
+ const call = await this.llm.call(_input);
49
+ const result = call.getResultContent();
50
+ return result;
51
+ }
52
+ getHandlerInput(_input) {
53
+ if (this.prompt) {
54
+ return this.prompt.format(_input || {});
55
+ }
56
+ if (this.promptFn) {
57
+ const prompt = this.promptFn(_input || {});
58
+ const promptFormatted = prompt.format(_input || {});
59
+ return promptFormatted;
60
+ }
61
+ throw new Error("Missing prompt");
62
+ }
63
+ getHandlerOutput(out, _metadata) {
64
+ return this.parser.parse(out, _metadata);
65
+ }
66
+ metadata() {
67
+ return {
68
+ llm: this.llm.getMetadata(),
69
+ };
70
+ }
71
+ }
72
+ exports.LlmExecutor = LlmExecutor;
73
+ //# sourceMappingURL=llm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm.js","sourceRoot":"src/","sources":["executor/llm.ts"],"names":[],"mappings":";;;AAQA,qCAAoD;AAIpD,mCAAuC;AAEvC;;GAEG;AACH,MAAa,WAKX,SAAQ,oBAAuD;IAM/D,YACE,gBAAoE,EACpE,OAAoC;QAEpC,KAAK,CACH,gBAAgB,CAAC,IAAI,IAAI,wBAAwB,EACjD,cAAc,EACd,OAAO,CACR,CAAC;QAbJ;;;;;WAAW;QACX;;;;;WAAc;QACd;;;;;WAAqB;QACrB;;;;;WAAc;QAYZ,IAAI,CAAC,GAAG,GAAG,gBAAgB,CAAC,GAAG,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,gBAAgB,EAAE,MAAM,IAAI,IAAI,qBAAY,EAAE,CAAC;QAE7D,IAAI,OAAO,gBAAgB,CAAC,MAAM,KAAK,UAAU,EAAE;YACjD,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;YACxB,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,MAAM,CAAC;SACzC;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC;YACtC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACtB;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAA2B;QACvC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,eAAe,CAAC,MAA2B;QACzC,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;SACzC;QAED,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;YAC3C,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;YACpD,OAAO,eAAe,CAAC;SACxB;QACD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;IAED,gBAAgB,CACd,GAAQ,EACR,SAGC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC3C,CAAC;IAED,QAAQ;QACN,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;SAC5B,CAAC;IACJ,CAAC;CACF;AAnED,kCAmEC"}
@@ -0,0 +1,61 @@
1
+ import { useExecutors, createCallableExecutor } from "./plugins/callable";
2
+ import { createCoreExecutor, createLlmExecutor } from "./executor/_functions";
3
+ import { BaseExecutor } from "./executor/_base";
4
+ import * as utils from "./utils";
5
+ import { BaseLlm, OpenAI, createLlmOpenAi } from "./llm";
6
+ import { EmbeddingOpenAI } from "./embedding/openai";
7
+ import { PineconeVectorStore } from "./vector";
8
+ import { BasePrompt, ChatPrompt, TextPrompt, createPrompt, createChatPrompt } from "./prompt";
9
+ import { BaseParser, CustomParser, createParser, createCustomParser } from "./parser";
10
+ import { DefaultState, BaseStateItem, DefaultStateItem, createState, createStateItem } from "./state";
11
+ export declare const simpleChain: {
12
+ /**
13
+ * Utilities
14
+ */
15
+ utils: typeof utils;
16
+ /**
17
+ * Llm
18
+ */
19
+ BaseLlm: typeof BaseLlm;
20
+ OpenAI: typeof OpenAI;
21
+ createLlmOpenAi: typeof createLlmOpenAi;
22
+ /**
23
+ * Prompt
24
+ */
25
+ BasePrompt: typeof BasePrompt;
26
+ TextPrompt: typeof TextPrompt;
27
+ ChatPrompt: typeof ChatPrompt;
28
+ createPrompt: typeof createPrompt;
29
+ createChatPrompt: typeof createChatPrompt;
30
+ /**
31
+ * Parsers
32
+ */
33
+ BaseParser: typeof BaseParser;
34
+ CustomParser: typeof CustomParser;
35
+ createParser: typeof createParser;
36
+ createCustomParser: typeof createCustomParser;
37
+ /**
38
+ * Core Functions
39
+ */
40
+ BaseExecutor: typeof BaseExecutor;
41
+ createCoreExecutor: typeof createCoreExecutor;
42
+ createLlmExecutor: typeof createLlmExecutor;
43
+ /**
44
+ * Callable
45
+ */
46
+ useExecutors: typeof useExecutors;
47
+ createCallableExecutor: typeof createCallableExecutor;
48
+ /**
49
+ * Embedding
50
+ */
51
+ EmbeddingOpenAI: typeof EmbeddingOpenAI;
52
+ PineconeVectorStore: typeof PineconeVectorStore;
53
+ /**
54
+ * State
55
+ */
56
+ DefaultState: typeof DefaultState;
57
+ BaseStateItem: typeof BaseStateItem;
58
+ DefaultStateItem: typeof DefaultStateItem;
59
+ createState: typeof createState;
60
+ createStateItem: typeof createStateItem;
61
+ };
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.simpleChain = void 0;
27
+ const callable_1 = require("./plugins/callable");
28
+ const _functions_1 = require("./executor/_functions");
29
+ const _base_1 = require("./executor/_base");
30
+ const utils = __importStar(require("./utils"));
31
+ const llm_1 = require("./llm");
32
+ const openai_1 = require("./embedding/openai");
33
+ const vector_1 = require("./vector");
34
+ const prompt_1 = require("./prompt");
35
+ const parser_1 = require("./parser");
36
+ const state_1 = require("./state");
37
+ exports.simpleChain = {
38
+ /**
39
+ * Utilities
40
+ */
41
+ utils,
42
+ /**
43
+ * Llm
44
+ */
45
+ BaseLlm: llm_1.BaseLlm,
46
+ OpenAI: llm_1.OpenAI,
47
+ createLlmOpenAi: llm_1.createLlmOpenAi,
48
+ /**
49
+ * Prompt
50
+ */
51
+ BasePrompt: prompt_1.BasePrompt,
52
+ TextPrompt: prompt_1.TextPrompt,
53
+ ChatPrompt: prompt_1.ChatPrompt,
54
+ createPrompt: prompt_1.createPrompt,
55
+ createChatPrompt: prompt_1.createChatPrompt,
56
+ /**
57
+ * Parsers
58
+ */
59
+ BaseParser: parser_1.BaseParser,
60
+ CustomParser: parser_1.CustomParser,
61
+ createParser: parser_1.createParser,
62
+ createCustomParser: parser_1.createCustomParser,
63
+ /**
64
+ * Core Functions
65
+ */
66
+ BaseExecutor: _base_1.BaseExecutor,
67
+ createCoreExecutor: _functions_1.createCoreExecutor,
68
+ createLlmExecutor: _functions_1.createLlmExecutor,
69
+ /**
70
+ * Callable
71
+ */
72
+ useExecutors: callable_1.useExecutors,
73
+ createCallableExecutor: callable_1.createCallableExecutor,
74
+ /**
75
+ * Embedding
76
+ */
77
+ EmbeddingOpenAI: openai_1.EmbeddingOpenAI,
78
+ PineconeVectorStore: vector_1.PineconeVectorStore,
79
+ /**
80
+ * State
81
+ */
82
+ DefaultState: state_1.DefaultState,
83
+ BaseStateItem: state_1.BaseStateItem,
84
+ DefaultStateItem: state_1.DefaultStateItem,
85
+ createState: state_1.createState,
86
+ createStateItem: state_1.createStateItem,
87
+ };
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0E;AAC1E,sDAA8E;AAC9E,4CAAgD;AAChD,+CAAiC;AACjC,+BAAyD;AACzD,+CAAqD;AACrD,qCAA+C;AAE/C,qCAMkB;AAElB,qCAKkB;AAElB,mCAMiB;AAEJ,QAAA,WAAW,GAAG;IACzB;;OAEG;IACH,KAAK;IACL;;OAEG;IACH,OAAO,EAAP,aAAO;IACP,MAAM,EAAN,YAAM;IACN,eAAe,EAAf,qBAAe;IACf;;OAEG;IACH,UAAU,EAAV,mBAAU;IACV,UAAU,EAAV,mBAAU;IACV,UAAU,EAAV,mBAAU;IACV,YAAY,EAAZ,qBAAY;IACZ,gBAAgB,EAAhB,yBAAgB;IAChB;;OAEG;IACH,UAAU,EAAV,mBAAU;IACV,YAAY,EAAZ,qBAAY;IACZ,YAAY,EAAZ,qBAAY;IACZ,kBAAkB,EAAlB,2BAAkB;IAClB;;OAEG;IACH,YAAY,EAAZ,oBAAY;IACZ,kBAAkB,EAAlB,+BAAkB;IAClB,iBAAiB,EAAjB,8BAAiB;IAEjB;;OAEG;IACH,YAAY,EAAZ,uBAAY;IACZ,sBAAsB,EAAtB,iCAAsB;IACtB;;OAEG;IACH,eAAe,EAAf,wBAAe;IACf,mBAAmB,EAAnB,4BAAmB;IACnB;;OAEG;IACH,YAAY,EAAZ,oBAAY;IACZ,aAAa,EAAb,qBAAa;IACb,gBAAgB,EAAhB,wBAAgB;IAChB,WAAW,EAAX,mBAAW;IACX,eAAe,EAAf,uBAAe;CAChB,CAAC"}
@@ -0,0 +1,19 @@
1
+ export type IChatMessageRole = "system" | "assistant" | "user";
2
+ export interface IChatMessageBase {
3
+ role: IChatMessageRole;
4
+ content: string;
5
+ }
6
+ export interface IChatUserMessage extends IChatMessageBase {
7
+ role: Extract<IChatMessageRole, "user">;
8
+ content: string;
9
+ name?: string;
10
+ }
11
+ export interface IChatAssistantMessage extends IChatMessageBase {
12
+ role: Extract<IChatMessageRole, "assistant">;
13
+ content: string;
14
+ }
15
+ export interface IChatSystemMessage extends IChatMessageBase {
16
+ role: Extract<IChatMessageRole, "system">;
17
+ content: string;
18
+ }
19
+ export type IChatMessages = (IChatUserMessage | IChatAssistantMessage | IChatSystemMessage)[];
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.js","sourceRoot":"src/","sources":["interfaces/chat.ts"],"names":[],"mappings":""}
@@ -0,0 +1,72 @@
1
+ import { BaseParser } from "../parser";
2
+ import { BasePrompt } from "../prompt";
3
+ import { PlainObject } from "./utils";
4
+ import { BaseExecutor } from "../executor";
5
+ export type ParserOutput<P> = P extends BaseParser<infer T> ? T : never;
6
+ export type PromptInput<P> = P extends BasePrompt<infer T> ? T : never;
7
+ export interface CoreExecutorExecuteOptions {
8
+ hooks?: CoreExecutorHookInput;
9
+ }
10
+ export interface ExecutorWithLlmOptions<Llm, Prompt, Parser, State> {
11
+ name?: string;
12
+ llm: Llm;
13
+ prompt: Prompt | ((values: PromptInput<Prompt>) => Prompt);
14
+ parser?: Parser;
15
+ state?: State;
16
+ __mock_response_key__?: string;
17
+ }
18
+ export interface CoreExecutorInput<I, O> {
19
+ name?: string;
20
+ handler: (input: I) => Promise<O> | O;
21
+ getHandlerInput?(input: I): any;
22
+ getHandlerOutput?(out: any): O;
23
+ }
24
+ export type FunctionOrExecutor<I extends PlainObject | {
25
+ input: string;
26
+ }, O> = ((input: I) => Promise<O> | O) | BaseExecutor<I, O>;
27
+ export interface ExecutorMetadata {
28
+ id: string;
29
+ type: string;
30
+ name: string;
31
+ created: number;
32
+ executions: number;
33
+ metadata?: Record<string, any>;
34
+ }
35
+ export interface Temporary {
36
+ id: string;
37
+ initialInput?: any;
38
+ currentStepNumber: number;
39
+ results: any[];
40
+ attributes: any;
41
+ }
42
+ export interface ExecutorExecutionMetadata<I = any, O = any> {
43
+ start: null | number;
44
+ end: null | number;
45
+ input: I;
46
+ handlerInput?: any;
47
+ handlerOutput?: any;
48
+ output?: O;
49
+ _handlerOutput: any[];
50
+ _output: O[];
51
+ errorMessage?: string;
52
+ error?: Error;
53
+ metadata?: null | ExecutorMetadata | Temporary;
54
+ }
55
+ export type ExecutorExecutionMetadataProperties = Pick<ExecutorExecutionMetadata, "start" | "end" | "input" | "handlerInput" | "handlerOutput" | "output" | "_handlerOutput" | "_output" | "errorMessage" | "error" | "metadata">;
56
+ export interface ExecutorContext<I = any, O = any, A = Record<string, any>> extends ExecutorExecutionMetadata<I, O> {
57
+ metadata: ExecutorMetadata;
58
+ attributes: A;
59
+ }
60
+ export interface CoreExecutorHookMethods<I = any, O = any> {
61
+ onError?(execution: ExecutorExecutionMetadata<I, O>, context?: any): void;
62
+ onComplete?(execution: ExecutorExecutionMetadata<I, O>, context?: any): void;
63
+ filterResult?<O>(output: O, execution?: ExecutorExecutionMetadata<I, O>, context?: any): O;
64
+ }
65
+ export type CoreExecutorHooks = {
66
+ [K in keyof CoreExecutorHookMethods]: CoreExecutorHookMethods[K][];
67
+ };
68
+ export interface CoreExecutorHookInput {
69
+ onError?: (execution: ExecutorExecutionMetadata, context?: any) => void | ((execution: ExecutorExecutionMetadata, context?: any) => void)[];
70
+ onComplete?: (execution: ExecutorExecutionMetadata, context?: any) => void | ((execution: ExecutorExecutionMetadata, context?: any) => void)[];
71
+ filterResult?: <O>(output: O, execution: ExecutorExecutionMetadata, context?: any) => O | (<O>(output: O, execution: ExecutorExecutionMetadata, context?: any) => O)[];
72
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"src/","sources":["interfaces/functions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export * from "./utils";
2
+ export * from "./chat";
3
+ export * from "./openai";
4
+ export * from "./functions";
5
+ export * from "./prompt";
6
+ export * from "./parser";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./utils"), exports);
18
+ __exportStar(require("./chat"), exports);
19
+ __exportStar(require("./openai"), exports);
20
+ __exportStar(require("./functions"), exports);
21
+ __exportStar(require("./prompt"), exports);
22
+ __exportStar(require("./parser"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,yCAAuB;AACvB,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,2CAAyB"}
@@ -0,0 +1,33 @@
1
+ import { PromptType } from "./prompt";
2
+ export interface BaseLlmOptions {
3
+ timeout?: number;
4
+ maxDelay?: number;
5
+ numOfAttempts?: number;
6
+ jitter?: "none" | "full";
7
+ promptType?: PromptType;
8
+ }
9
+ export type OpenAIChatModelName = "gpt-3.5-turbo" | "gpt-4";
10
+ export type OpenAIConversationModelName = "davinci" | "text-curie-001" | "text-babbage-001" | "text-ada-001";
11
+ export type OpenAIEmbeddingModelName = "text-embedding-ada-002";
12
+ export type OpenAIModelName = OpenAIChatModelName | OpenAIConversationModelName | OpenAIEmbeddingModelName;
13
+ export interface OpenAIOptions extends BaseLlmOptions {
14
+ openAIApiKey: string;
15
+ modelName: OpenAIModelName;
16
+ maxTokens?: number;
17
+ temperature?: number;
18
+ topP?: number | null;
19
+ n?: number | null;
20
+ stream?: boolean | null;
21
+ stop?: any;
22
+ max_tokens?: number;
23
+ presencePenalty?: number | null;
24
+ frequencyPenalty?: number | null;
25
+ logitBias?: object | null;
26
+ user?: string;
27
+ }
28
+ export interface EmbedOpenAIOptions extends OpenAIOptions {
29
+ openAIApiKey: string;
30
+ modelName: OpenAIModelName;
31
+ batchSize?: number;
32
+ stripNewLines?: boolean;
33
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sourceRoot":"src/","sources":["interfaces/openai.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { JSONSchema7 } from "json-schema-to-ts";
2
+ export type CreateParserType = "json" | "string" | "boolean" | "number" | "listToArray" | "listToJson" | "listToKeyValue" | "replaceStringTemplate" | "markdownCodeBlocks" | "markdownCodeBlock";
3
+ export interface ParserOptionsWithSchema {
4
+ schema?: JSONSchema7;
5
+ }
6
+ export interface BaseParserOptions {
7
+ schema?: JSONSchema7;
8
+ }
9
+ export interface BaseParserOptionsWithSchema<S extends JSONSchema7 | undefined = undefined> extends BaseParserOptions {
10
+ schema?: S;
11
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"src/","sources":["interfaces/parser.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ export type TextPromptType = "text";
2
+ export type ChatPromptType = "chat";
3
+ export type PromptType = TextPromptType | ChatPromptType;
4
+ export type PromptHelper = {
5
+ name: string;
6
+ handler: (args: any) => any;
7
+ };
8
+ export type PromptPartial = {
9
+ name: string;
10
+ template: string;
11
+ };
12
+ export interface PromptTemplateOptions {
13
+ partials?: PromptPartial[];
14
+ helpers?: PromptHelper[];
15
+ }
16
+ export interface PromptOptions extends PromptTemplateOptions {
17
+ }
18
+ export interface ChatPromptOptions extends PromptOptions {
19
+ allowUnsafeUserTemplate?: boolean;
20
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"src/","sources":["interfaces/prompt.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ export type PrimitiveValue = bigint | boolean | null | number | string | symbol | undefined;
2
+ export type ObjectValue = PrimitiveValue | PlainObject | ObjectArray;
3
+ export interface PlainObject {
4
+ [key: string]: ObjectValue;
5
+ }
6
+ export interface ObjectArray extends Array<ObjectValue> {
7
+ }
8
+ export interface ResultAttributes<R = any, A = Record<string, any>> {
9
+ result: R;
10
+ attributes: A;
11
+ }
12
+ export interface Serializable {
13
+ serialize?(): Record<string, any>;
14
+ deserialize?(): void;
15
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"src/","sources":["interfaces/utils.ts"],"names":[],"mappings":""}
@@ -0,0 +1,78 @@
1
+ import { BaseLlmOptions, PromptType } from "../types";
2
+ import { BaseLlmOutput } from "../llm/output";
3
+ /**
4
+ * BaseLlm is an abstract class that provides a base structure for implementing
5
+ * specific Low Latency Models (LLMs). It handles retries, timeouts, and metrics
6
+ * for the calls made to the LLM.
7
+ */
8
+ export declare abstract class BaseLlm<C = any> {
9
+ /**
10
+ * A property to hold the client instance for the specific LLM.
11
+ */
12
+ protected client: C;
13
+ /**
14
+ * The type of prompt to create. Options are "text" or "chat"
15
+ */
16
+ protected promptType: PromptType;
17
+ /**
18
+ * The maximum time (in milliseconds) to wait for a response before timing out.
19
+ */
20
+ protected timeout: number;
21
+ /**
22
+ * The maximum delay (in milliseconds) between retries.
23
+ */
24
+ protected maxDelay: number;
25
+ /**
26
+ * The maximum number of retries before giving up.
27
+ */
28
+ protected numOfAttempts: number;
29
+ /**
30
+ * The jitter strategy to use between retries. Options are "none" or "full".
31
+ */
32
+ protected jitter: "none" | "full";
33
+ /**
34
+ * An object to store metrics related to the LLM calls.
35
+ */
36
+ protected metrics: any;
37
+ /**
38
+ * The BaseLlm constructor takes an options object and sets up the instance.
39
+ * @param {BaseLlmOptions} options - The options object for LLM configuration.
40
+ */
41
+ constructor(options: BaseLlmOptions);
42
+ getPromptType(): PromptType;
43
+ /**
44
+ * getMetrics returns the metrics object for the LLM.
45
+ */
46
+ getMetrics(): any;
47
+ /**
48
+ * getMetadata - Used to return metrics and data about executions.
49
+ */
50
+ getMetadata(): {
51
+ promptType: PromptType;
52
+ timeout: number;
53
+ jitter: "none" | "full";
54
+ maxDelay: number;
55
+ numOfAttempts: number;
56
+ metrics: any;
57
+ };
58
+ /**
59
+ * call makes a call to the specific LLM with input and returns the output.
60
+ * It also handles retries and updates the metrics.
61
+ * @param _input - The input to the LLM.
62
+ * @return The output from the LLM.
63
+ */
64
+ call(_input: any, attributes?: Record<string, any>): Promise<BaseLlmOutput>;
65
+ /**
66
+ * _callWithRetry is a private method that handles retries and timeouts for the LLM call.
67
+ * @param _input - The input to the LLM.
68
+ * @return The result of the LLM call.
69
+ * @throws An error if the maximum number of retries is reached.
70
+ */
71
+ _callWithRetry(_input: any, attributes?: Record<string, any>): Promise<any>;
72
+ /**
73
+ * _call is an abstract method that must be implemented by subclasses to make the actual LLM call.
74
+ * @param {any} _input - The input to the LLM.
75
+ * @return The output from the LLM.
76
+ */
77
+ _call(_input: any, _attributes?: Record<string, any>): Promise<BaseLlmOutput>;
78
+ }