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,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createChatPrompt = exports.createPrompt = void 0;
4
+ const text_1 = require("./text");
5
+ const chat_1 = require("./chat");
6
+ function createPrompt(type, initialPromptMessage, options) {
7
+ switch (type) {
8
+ case "chat":
9
+ return new chat_1.ChatPrompt(initialPromptMessage, options);
10
+ default:
11
+ return new text_1.TextPrompt(initialPromptMessage);
12
+ }
13
+ }
14
+ exports.createPrompt = createPrompt;
15
+ /**
16
+ * `createChatPrompt` Creates a new instance of a chat prompt.
17
+ *
18
+ * @param initialSystemPromptMessage (optional) A message to use for an initial system message.
19
+ */
20
+ function createChatPrompt(initialSystemPromptMessage, options) {
21
+ return new chat_1.ChatPrompt(initialSystemPromptMessage, options);
22
+ }
23
+ exports.createChatPrompt = createChatPrompt;
24
+ //# sourceMappingURL=_functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_functions.js","sourceRoot":"src/","sources":["prompt/_functions.ts"],"names":[],"mappings":";;;AAEA,iCAAoC;AACpC,iCAAoC;AAwBpC,SAAgB,YAAY,CAC1B,IAAiB,EACjB,oBAA6B,EAC7B,OAA2C;IAE3C,QAAQ,IAAI,EAAE;QACZ,KAAK,MAAM;YACT,OAAO,IAAI,iBAAU,CAAI,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC1D;YACE,OAAO,IAAI,iBAAU,CAAI,oBAAoB,CAAC,CAAC;KAClD;AACH,CAAC;AAXD,oCAWC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAC9B,0BAAmC,EACnC,OAA2B;IAE3B,OAAO,IAAI,iBAAU,CAAI,0BAA0B,EAAE,OAAO,CAAC,CAAC;AAChE,CAAC;AALD,4CAKC"}
@@ -0,0 +1,68 @@
1
+ import { BasePrompt } from "./_base";
2
+ import { IChatMessages, IChatMessageRole, ChatPromptType, ChatPromptOptions } from "../types";
3
+ /**
4
+ * `ChatPrompt` provides a conversation-style prompt enabling various roles.
5
+ * The chat prompt can be used with models such as gpt-3.5.turbo and gpt-4.
6
+ * @extends BasePrompt
7
+ */
8
+ export declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
9
+ /**
10
+ * @property type - Prompt type (chat)
11
+ */
12
+ readonly type: ChatPromptType;
13
+ /**
14
+ * @property parseUserTemplates - Whether or not to allow parsing
15
+ * user messages with the template engine. This could be a risk,
16
+ * so we only parse user messages if explicitly set.
17
+ */
18
+ private parseUserTemplates;
19
+ /**
20
+ * new `ChatPrompt`
21
+ * @param initialSystemPromptMessage (optional) An initial system message to add to the new prompt.
22
+ * @param options (optional) Options to pass in when creating the prompt.
23
+ */
24
+ constructor(initialSystemPromptMessage?: string, options?: ChatPromptOptions);
25
+ /**
26
+ * addToPrompt Adds a message to the prompt based on role.
27
+ * @param content The message content.
28
+ * @param role The role of the chat user. Must be one of: assistant, system, user.
29
+ * @param name (optional) The name of the user. Only accepted if role is `user`.
30
+ * @return instance of BasePrompt.
31
+ */
32
+ addToPrompt(content: string, role: Extract<IChatMessageRole, "assistant">, name?: undefined): BasePrompt<I>;
33
+ addToPrompt(content: string, role: Extract<IChatMessageRole, "system">, name?: undefined): BasePrompt<I>;
34
+ addToPrompt(content: string, role: Extract<IChatMessageRole, "user">, name?: string): BasePrompt<I>;
35
+ /**
36
+ * addUserMessage Helper to add a user message to the prompt.
37
+ * @param content The message content.
38
+ * @param name (optional) The name of the user.
39
+ * @return instance of BasePrompt.
40
+ */
41
+ addUserMessage(content: string, name?: string): ChatPrompt<I>;
42
+ /**
43
+ * addAssistantMessage Helper to add an assistant message to the prompt.
44
+ * @param content The message content.
45
+ * @return ChatPrompt so it can be chained.
46
+ */
47
+ addAssistantMessage(content: string): ChatPrompt<I>;
48
+ /**
49
+ * addFromHistory Adds multiple messages at one time.
50
+ * @param history History of chat messages.
51
+ * @return ChatPrompt so it can be chained.
52
+ */
53
+ addFromHistory(history: IChatMessages): ChatPrompt<I>;
54
+ /**
55
+ * format formats the stored prompt based on input values.
56
+ * Uses template engine.
57
+ * Output is intended for LLM.
58
+ * @param values input values.
59
+ * @return formatted prompt.
60
+ */
61
+ format(values: I): IChatMessages;
62
+ /**
63
+ * validate Ensures there are not unresolved tokens in prompt.
64
+ * @TODO Make this work!
65
+ * @return Returns false if the template is not valid.
66
+ */
67
+ validate(): boolean;
68
+ }
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatPrompt = void 0;
4
+ const utils_1 = require("../utils");
5
+ const _base_1 = require("./_base");
6
+ /**
7
+ * `ChatPrompt` provides a conversation-style prompt enabling various roles.
8
+ * The chat prompt can be used with models such as gpt-3.5.turbo and gpt-4.
9
+ * @extends BasePrompt
10
+ */
11
+ class ChatPrompt extends _base_1.BasePrompt {
12
+ /**
13
+ * new `ChatPrompt`
14
+ * @param initialSystemPromptMessage (optional) An initial system message to add to the new prompt.
15
+ * @param options (optional) Options to pass in when creating the prompt.
16
+ */
17
+ constructor(initialSystemPromptMessage, options) {
18
+ super(initialSystemPromptMessage);
19
+ /**
20
+ * @property type - Prompt type (chat)
21
+ */
22
+ Object.defineProperty(this, "type", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: "chat"
27
+ });
28
+ /**
29
+ * @property parseUserTemplates - Whether or not to allow parsing
30
+ * user messages with the template engine. This could be a risk,
31
+ * so we only parse user messages if explicitly set.
32
+ */
33
+ Object.defineProperty(this, "parseUserTemplates", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: false
38
+ });
39
+ if (options?.allowUnsafeUserTemplate) {
40
+ this.parseUserTemplates = true;
41
+ }
42
+ }
43
+ addToPrompt(content, role, name) {
44
+ if (content) {
45
+ switch (role) {
46
+ case "system":
47
+ this.addSystemMessage(content);
48
+ break;
49
+ case "user":
50
+ this.addUserMessage(content, name);
51
+ break;
52
+ case "assistant":
53
+ this.addAssistantMessage(content);
54
+ break;
55
+ }
56
+ }
57
+ return this;
58
+ }
59
+ /**
60
+ * addUserMessage Helper to add a user message to the prompt.
61
+ * @param content The message content.
62
+ * @param name (optional) The name of the user.
63
+ * @return instance of BasePrompt.
64
+ */
65
+ addUserMessage(content, name) {
66
+ const message = {
67
+ role: "user",
68
+ content,
69
+ };
70
+ if (name) {
71
+ message.name = name;
72
+ }
73
+ this.messages.push(message);
74
+ return this;
75
+ }
76
+ /**
77
+ * addAssistantMessage Helper to add an assistant message to the prompt.
78
+ * @param content The message content.
79
+ * @return ChatPrompt so it can be chained.
80
+ */
81
+ addAssistantMessage(content) {
82
+ this.messages.push({
83
+ role: "assistant",
84
+ content,
85
+ });
86
+ return this;
87
+ }
88
+ /**
89
+ * addFromHistory Adds multiple messages at one time.
90
+ * @param history History of chat messages.
91
+ * @return ChatPrompt so it can be chained.
92
+ */
93
+ addFromHistory(history) {
94
+ if (history) {
95
+ this.messages.push(...history);
96
+ }
97
+ return this;
98
+ }
99
+ /**
100
+ * format formats the stored prompt based on input values.
101
+ * Uses template engine.
102
+ * Output is intended for LLM.
103
+ * @param values input values.
104
+ * @return formatted prompt.
105
+ */
106
+ format(values) {
107
+ const replacements = this.getReplacements(values);
108
+ const safeToParseTemplate = ["assistant", "system"];
109
+ if (this.parseUserTemplates) {
110
+ safeToParseTemplate.push("user");
111
+ }
112
+ return this.messages.map((message) => {
113
+ if (safeToParseTemplate.includes(message.role)) {
114
+ return {
115
+ role: message.role,
116
+ content: (0, utils_1.replaceTemplateString)(message.content, replacements, {
117
+ partials: this.partials,
118
+ helpers: this.helpers,
119
+ }),
120
+ };
121
+ }
122
+ return message;
123
+ });
124
+ }
125
+ /**
126
+ * validate Ensures there are not unresolved tokens in prompt.
127
+ * @TODO Make this work!
128
+ * @return Returns false if the template is not valid.
129
+ */
130
+ validate() {
131
+ // add validation for missing tokens, etc.
132
+ return true;
133
+ }
134
+ }
135
+ exports.ChatPrompt = ChatPrompt;
136
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.js","sourceRoot":"src/","sources":["prompt/chat.ts"],"names":[],"mappings":";;;AAAA,mCAAgD;AAChD,mCAAqC;AASrC;;;;GAIG;AACH,MAAa,UAA0C,SAAQ,kBAAa;IAa1E;;;;OAIG;IACH,YACE,0BAAmC,EACnC,OAA2B;QAE3B,KAAK,CAAC,0BAA0B,CAAC,CAAC;QArBpC;;WAEG;QACH;;;;mBAAgC,MAAM;WAAC;QAEvC;;;;WAIG;QACH;;;;mBAA6B,KAAK;WAAC;QAajC,IAAI,OAA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mB,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAEpD,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAClC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACnC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBAC9C,OAAO;oBACL,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,OAAO,EAAE,IAAA,6BAAqB,EAAC,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE;wBAC5D,QAAQ,EAAE,IAAI,CAAC,QAAQ;wBACvB,OAAO,EAAE,IAAI,CAAC,OAAO;qBACtB,CAAC;iBACH,CAAC;aACH;YACD,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;IACD;;;;OAIG;IACH,QAAQ;QACN,0CAA0C;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAxJD,gCAwJC"}
@@ -0,0 +1,4 @@
1
+ export { BasePrompt } from "./_base";
2
+ export { TextPrompt } from "./text";
3
+ export { ChatPrompt } from "./chat";
4
+ export { createPrompt, createChatPrompt } from "./_functions";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createChatPrompt = exports.createPrompt = exports.ChatPrompt = exports.TextPrompt = exports.BasePrompt = void 0;
4
+ var _base_1 = require("./_base");
5
+ Object.defineProperty(exports, "BasePrompt", { enumerable: true, get: function () { return _base_1.BasePrompt; } });
6
+ var text_1 = require("./text");
7
+ Object.defineProperty(exports, "TextPrompt", { enumerable: true, get: function () { return text_1.TextPrompt; } });
8
+ var chat_1 = require("./chat");
9
+ Object.defineProperty(exports, "ChatPrompt", { enumerable: true, get: function () { return chat_1.ChatPrompt; } });
10
+ var _functions_1 = require("./_functions");
11
+ Object.defineProperty(exports, "createPrompt", { enumerable: true, get: function () { return _functions_1.createPrompt; } });
12
+ Object.defineProperty(exports, "createChatPrompt", { enumerable: true, get: function () { return _functions_1.createChatPrompt; } });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["prompt/index.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAA5B,mGAAA,UAAU,OAAA;AACnB,+BAAoC;AAA3B,kGAAA,UAAU,OAAA;AACnB,+BAAoC;AAA3B,kGAAA,UAAU,OAAA;AACnB,2CAA8D;AAArD,0GAAA,YAAY,OAAA;AAAE,8GAAA,gBAAgB,OAAA"}
@@ -0,0 +1,9 @@
1
+ import { BasePrompt } from "./_base";
2
+ /**
3
+ * `TextPrompt` provides a standard text-based prompt.
4
+ * The text prompt can be used with models such as davinci.
5
+ * @extends BasePrompt
6
+ */
7
+ export declare class TextPrompt<I extends Record<string, any>> extends BasePrompt<I> {
8
+ constructor(base?: string);
9
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextPrompt = void 0;
4
+ const _base_1 = require("./_base");
5
+ /**
6
+ * `TextPrompt` provides a standard text-based prompt.
7
+ * The text prompt can be used with models such as davinci.
8
+ * @extends BasePrompt
9
+ */
10
+ class TextPrompt extends _base_1.BasePrompt {
11
+ constructor(base) {
12
+ super(base);
13
+ }
14
+ }
15
+ exports.TextPrompt = TextPrompt;
16
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"src/","sources":["prompt/text.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAErC;;;;GAIG;AACH,MAAa,UAA0C,SAAQ,kBAAa;IAC1E,YAAY,IAAa;QACvB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;CACF;AAJD,gCAIC"}
@@ -0,0 +1,29 @@
1
+ import { Dialogue } from "./dialogue";
2
+ import { BaseStateItem } from "./item";
3
+ export declare abstract class BaseState {
4
+ dialogues: {
5
+ [key in string]: Dialogue;
6
+ };
7
+ attributes: Record<string, any>;
8
+ context: Record<string, BaseStateItem<any>>;
9
+ constructor();
10
+ createDialogue(name?: string): Dialogue;
11
+ useDialogue(name?: string): Dialogue;
12
+ getDialogue(name?: string): Dialogue;
13
+ createContextItem<T extends BaseStateItem<any>>(item: T): T;
14
+ getContext<T>(key: string): BaseStateItem<T>;
15
+ getContextValue<T>(key: string): T;
16
+ setAttribute(key: string, value: any): void;
17
+ deleteAttribute(key: string): void;
18
+ clearAttributes(): void;
19
+ serialize(): {
20
+ dialogues: any;
21
+ context: any;
22
+ attributes: any;
23
+ };
24
+ abstract saveState(): Promise<void>;
25
+ }
26
+ export declare class DefaultState extends BaseState {
27
+ constructor();
28
+ saveState(): Promise<void>;
29
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultState = exports.BaseState = void 0;
4
+ const utils_1 = require("../utils");
5
+ const dialogue_1 = require("./dialogue");
6
+ const item_1 = require("./item");
7
+ class BaseState {
8
+ constructor() {
9
+ Object.defineProperty(this, "dialogues", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: {}
14
+ });
15
+ Object.defineProperty(this, "attributes", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: {}
20
+ });
21
+ Object.defineProperty(this, "context", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: {}
26
+ });
27
+ }
28
+ createDialogue(name = "defaultDialogue") {
29
+ (0, utils_1.assert)(!this.dialogues[name], `Dialogue already exists`);
30
+ this.dialogues[name] = new dialogue_1.Dialogue(name);
31
+ return this.dialogues[name];
32
+ }
33
+ useDialogue(name = "defaultDialogue") {
34
+ const dialogue = this.dialogues[name];
35
+ if (!dialogue) {
36
+ this.dialogues[name] = new dialogue_1.Dialogue(name);
37
+ return this.dialogues[name];
38
+ }
39
+ return dialogue;
40
+ }
41
+ getDialogue(name = "defaultDialogue") {
42
+ const dialogue = this.dialogues[name];
43
+ (0, utils_1.assert)(dialogue, `Invalid dialogue ${name}`);
44
+ return dialogue;
45
+ }
46
+ createContextItem(item) {
47
+ (0, utils_1.assert)(item instanceof item_1.BaseStateItem, "Invalid context item. Must be instance of BaseStateItem");
48
+ (0, utils_1.assert)(!this.context[item?.getKey()], `key (${item?.getKey()}) already exists`);
49
+ this.context[item.getKey()] = item;
50
+ return this.context[item.getKey()];
51
+ }
52
+ getContext(key) {
53
+ return this.context[key];
54
+ }
55
+ getContextValue(key) {
56
+ return this.context[key]?.getValue();
57
+ }
58
+ setAttribute(key, value) {
59
+ this.attributes[key] = value;
60
+ }
61
+ deleteAttribute(key) {
62
+ delete this.attributes[key];
63
+ }
64
+ clearAttributes() {
65
+ this.attributes = {};
66
+ }
67
+ serialize() {
68
+ const dialogues = {};
69
+ const context = { ...this.context };
70
+ const attributes = { ...this.attributes };
71
+ const dialogueKeys = Object.keys(this.dialogues);
72
+ for (const dialogueKey of dialogueKeys) {
73
+ dialogues[dialogueKey] = this.dialogues[dialogueKey].serialize();
74
+ }
75
+ return {
76
+ dialogues,
77
+ context,
78
+ attributes,
79
+ };
80
+ }
81
+ }
82
+ exports.BaseState = BaseState;
83
+ class DefaultState extends BaseState {
84
+ constructor() {
85
+ super();
86
+ }
87
+ async saveState() {
88
+ console.log("Save not implemented in default state.");
89
+ }
90
+ }
91
+ exports.DefaultState = DefaultState;
92
+ //# sourceMappingURL=_base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_base.js","sourceRoot":"src/","sources":["state/_base.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AACjC,yCAAsC;AACtC,iCAAuC;AAEvC,MAAsB,SAAS;IAK7B;QAJA;;;;mBAAkD,EAAE;WAAC;QACrD;;;;mBAAyC,EAAE;WAAC;QAC5C;;;;mBAAqD,EAAE;WAAC;IAEzC,CAAC;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;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAqB,CAAC;IAC/C,CAAC;IAED,eAAe,CAAI,GAAW;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvC,CAAC;IAED,YAAY,CAAC,GAAW,EAAE,KAAU;QAClC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC/B,CAAC;IAED,eAAe,CAAC,GAAW;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,eAAe;QACb,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,SAAS;QACP,MAAM,SAAS,GAAQ,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAQ,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACzC,MAAM,UAAU,GAAQ,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAE/C,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAC9B,IAAI,CAAC,SAAS,CACoB,CAAC;QACrC,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE;YACtC,SAAS,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,SAAS,EAAE,CAAC;SAClE;QAED,OAAO;YACL,SAAS;YACT,OAAO;YACP,UAAU;SACX,CAAC;IACJ,CAAC;CAGF;AA/ED,8BA+EC;AAED,MAAa,YAAa,SAAQ,SAAS;IACzC;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IACD,KAAK,CAAC,SAAS;QACb,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;IACxD,CAAC;CACF;AAPD,oCAOC"}
@@ -0,0 +1,6 @@
1
+ import { DefaultState } from ".";
2
+ import { Dialogue } from "./dialogue";
3
+ import { DefaultStateItem } from "./item";
4
+ export declare function createState(): DefaultState;
5
+ export declare function createDialogue(name: string): Dialogue;
6
+ export declare function createStateItem<T>(name: string, defaultValue: T): DefaultStateItem;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStateItem = exports.createDialogue = exports.createState = void 0;
4
+ const _1 = require(".");
5
+ const dialogue_1 = require("./dialogue");
6
+ const item_1 = require("./item");
7
+ function createState() {
8
+ return new _1.DefaultState();
9
+ }
10
+ exports.createState = createState;
11
+ function createDialogue(name) {
12
+ return new dialogue_1.Dialogue(name);
13
+ }
14
+ exports.createDialogue = createDialogue;
15
+ function createStateItem(name, defaultValue) {
16
+ return new item_1.DefaultStateItem(name, defaultValue);
17
+ }
18
+ exports.createStateItem = createStateItem;
19
+ //# sourceMappingURL=_functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_functions.js","sourceRoot":"src/","sources":["state/_functions.ts"],"names":[],"mappings":";;;AAAA,wBAAiC;AACjC,yCAAsC;AACtC,iCAA0C;AAE1C,SAAgB,WAAW;IACzB,OAAO,IAAI,eAAY,EAAE,CAAC;AAC5B,CAAC;AAFD,kCAEC;AACD,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAFD,wCAEC;AAED,SAAgB,eAAe,CAAI,IAAY,EAAE,YAAe;IAC9D,OAAO,IAAI,uBAAgB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AAClD,CAAC;AAFD,0CAEC"}
@@ -0,0 +1,17 @@
1
+ import { IChatMessages, IChatUserMessage } from "../types";
2
+ import { BaseStateItem } from "./item";
3
+ export declare class Dialogue extends BaseStateItem<IChatMessages> {
4
+ name: string;
5
+ constructor(name: string);
6
+ setUserMessage(content: string, name?: string): this;
7
+ setAssistantMessage(content: string): this;
8
+ setSystemMessage(content: string): this;
9
+ setMessageTurn(userMessage: string, assistantMessage: string, systemMessage?: string): this;
10
+ getHistory(): IChatMessages;
11
+ serialize(): {
12
+ class: string;
13
+ name: string;
14
+ value: (IChatUserMessage | import("../types").IChatAssistantMessage | import("../types").IChatSystemMessage)[];
15
+ };
16
+ deserialize(): void;
17
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Dialogue = void 0;
4
+ const item_1 = require("./item");
5
+ class Dialogue extends item_1.BaseStateItem {
6
+ constructor(name) {
7
+ super(name, []);
8
+ Object.defineProperty(this, "name", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: void 0
13
+ });
14
+ this.name = name;
15
+ }
16
+ setUserMessage(content, name) {
17
+ if (content) {
18
+ const msg = {
19
+ role: "user",
20
+ content,
21
+ };
22
+ if (name) {
23
+ msg.name = name;
24
+ }
25
+ this.value.push(msg);
26
+ }
27
+ return this;
28
+ }
29
+ setAssistantMessage(content) {
30
+ if (content) {
31
+ this.value.push({
32
+ role: "assistant",
33
+ content,
34
+ });
35
+ }
36
+ return this;
37
+ }
38
+ setSystemMessage(content) {
39
+ if (content) {
40
+ this.value.push({
41
+ role: "system",
42
+ content,
43
+ });
44
+ }
45
+ return this;
46
+ }
47
+ setMessageTurn(userMessage, assistantMessage, systemMessage = "") {
48
+ this.setUserMessage(userMessage);
49
+ this.setAssistantMessage(assistantMessage);
50
+ this.setSystemMessage(systemMessage);
51
+ return this;
52
+ }
53
+ getHistory() {
54
+ return this.getValue();
55
+ }
56
+ serialize() {
57
+ return {
58
+ class: "Dialogue",
59
+ name: this.name,
60
+ value: [...this.value],
61
+ };
62
+ }
63
+ deserialize() { }
64
+ }
65
+ exports.Dialogue = Dialogue;
66
+ //# sourceMappingURL=dialogue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialogue.js","sourceRoot":"src/","sources":["state/dialogue.ts"],"names":[],"mappings":";;;AACA,iCAAuC;AAEvC,MAAa,QAAS,SAAQ,oBAA4B;IAGxD,YAAY,IAAY;QACtB,KAAK,CAAC,IAAI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IACJ,CAAC;IACD,WAAW,KAAI,CAAC;CACjB;AAjED,4BAiEC"}
@@ -0,0 +1,4 @@
1
+ export { BaseStateItem, DefaultStateItem } from "./item";
2
+ export { Dialogue } from "./dialogue";
3
+ export { BaseState, DefaultState } from "./_base";
4
+ export { createState, createDialogue, createStateItem } from "./_functions";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStateItem = exports.createDialogue = exports.createState = exports.DefaultState = exports.BaseState = exports.Dialogue = exports.DefaultStateItem = exports.BaseStateItem = void 0;
4
+ var item_1 = require("./item");
5
+ Object.defineProperty(exports, "BaseStateItem", { enumerable: true, get: function () { return item_1.BaseStateItem; } });
6
+ Object.defineProperty(exports, "DefaultStateItem", { enumerable: true, get: function () { return item_1.DefaultStateItem; } });
7
+ var dialogue_1 = require("./dialogue");
8
+ Object.defineProperty(exports, "Dialogue", { enumerable: true, get: function () { return dialogue_1.Dialogue; } });
9
+ var _base_1 = require("./_base");
10
+ Object.defineProperty(exports, "BaseState", { enumerable: true, get: function () { return _base_1.BaseState; } });
11
+ Object.defineProperty(exports, "DefaultState", { enumerable: true, get: function () { return _base_1.DefaultState; } });
12
+ var _functions_1 = require("./_functions");
13
+ Object.defineProperty(exports, "createState", { enumerable: true, get: function () { return _functions_1.createState; } });
14
+ Object.defineProperty(exports, "createDialogue", { enumerable: true, get: function () { return _functions_1.createDialogue; } });
15
+ Object.defineProperty(exports, "createStateItem", { enumerable: true, get: function () { return _functions_1.createStateItem; } });
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["state/index.ts"],"names":[],"mappings":";;;AAAA,+BAAyD;AAAhD,qGAAA,aAAa,OAAA;AAAE,wGAAA,gBAAgB,OAAA;AACxC,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,iCAAkD;AAAzC,kGAAA,SAAS,OAAA;AAAE,qGAAA,YAAY,OAAA;AAChC,2CAA4E;AAAnE,yGAAA,WAAW,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,6GAAA,eAAe,OAAA"}
@@ -0,0 +1,23 @@
1
+ import { Serializable } from "../types";
2
+ export declare abstract class BaseStateItem<T> implements Serializable {
3
+ protected key: string;
4
+ protected value: T;
5
+ protected initialValue: T;
6
+ constructor(key: string, initialValue: T);
7
+ setValue(value: T): void;
8
+ getKey(): string;
9
+ getValue(): T;
10
+ resetValue(): void;
11
+ serializeValue(): {
12
+ [x: string]: T;
13
+ };
14
+ serialize(): {
15
+ class: string;
16
+ name: string;
17
+ value: any;
18
+ };
19
+ deserialize(): void;
20
+ }
21
+ export declare class DefaultStateItem extends BaseStateItem<any> {
22
+ constructor(name: string, defaultValue: any);
23
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultStateItem = exports.BaseStateItem = void 0;
4
+ const utils_1 = require("../utils");
5
+ class BaseStateItem {
6
+ constructor(key, initialValue) {
7
+ Object.defineProperty(this, "key", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: void 0
12
+ });
13
+ Object.defineProperty(this, "value", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ Object.defineProperty(this, "initialValue", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ this.key = key;
26
+ this.value = initialValue;
27
+ this.initialValue = initialValue;
28
+ }
29
+ setValue(value) {
30
+ (0, utils_1.assert)(typeof value === typeof this.value, `Invalid value type. Expected ${typeof this
31
+ .value}, received ${typeof value}`);
32
+ this.value = value;
33
+ }
34
+ getKey() {
35
+ return this.key;
36
+ }
37
+ getValue() {
38
+ return this.value;
39
+ }
40
+ resetValue() {
41
+ this.value = this.initialValue;
42
+ }
43
+ serializeValue() {
44
+ return {
45
+ [this.getKey()]: this.getValue(),
46
+ };
47
+ }
48
+ serialize() {
49
+ return {
50
+ class: "BaseStateItem",
51
+ name: this.getKey(),
52
+ value: this.serializeValue(),
53
+ };
54
+ }
55
+ deserialize() { }
56
+ }
57
+ exports.BaseStateItem = BaseStateItem;
58
+ class DefaultStateItem extends BaseStateItem {
59
+ constructor(name, defaultValue) {
60
+ super(name, defaultValue);
61
+ }
62
+ }
63
+ exports.DefaultStateItem = DefaultStateItem;
64
+ //# sourceMappingURL=item.js.map