langchain 0.0.76 → 0.0.78

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 (162) hide show
  1. package/chains/query_constructor/ir.cjs +1 -0
  2. package/chains/query_constructor/ir.d.ts +1 -0
  3. package/chains/query_constructor/ir.js +1 -0
  4. package/chains/query_constructor.cjs +1 -0
  5. package/chains/query_constructor.d.ts +1 -0
  6. package/chains/query_constructor.js +1 -0
  7. package/dist/agents/agent.d.ts +5 -4
  8. package/dist/agents/agent_toolkits/sql/sql.cjs +2 -2
  9. package/dist/agents/agent_toolkits/sql/sql.d.ts +1 -1
  10. package/dist/agents/agent_toolkits/sql/sql.js +2 -2
  11. package/dist/agents/chat/index.cjs +3 -3
  12. package/dist/agents/chat/index.d.ts +1 -0
  13. package/dist/agents/chat/index.js +3 -3
  14. package/dist/agents/chat_convo/index.cjs +30 -14
  15. package/dist/agents/chat_convo/index.d.ts +5 -1
  16. package/dist/agents/chat_convo/index.js +31 -15
  17. package/dist/agents/chat_convo/outputParser.cjs +79 -7
  18. package/dist/agents/chat_convo/outputParser.d.ts +25 -13
  19. package/dist/agents/chat_convo/outputParser.js +77 -6
  20. package/dist/agents/chat_convo/prompt.cjs +11 -8
  21. package/dist/agents/chat_convo/prompt.d.ts +2 -2
  22. package/dist/agents/chat_convo/prompt.js +11 -8
  23. package/dist/agents/executor.d.ts +2 -3
  24. package/dist/agents/index.cjs +6 -1
  25. package/dist/agents/index.d.ts +2 -0
  26. package/dist/agents/index.js +2 -0
  27. package/dist/agents/initialize.cjs +19 -13
  28. package/dist/agents/initialize.d.ts +12 -2
  29. package/dist/agents/initialize.js +16 -10
  30. package/dist/agents/mrkl/index.cjs +3 -3
  31. package/dist/agents/mrkl/index.d.ts +1 -0
  32. package/dist/agents/mrkl/index.js +3 -3
  33. package/dist/agents/mrkl/outputParser.cjs +2 -2
  34. package/dist/agents/mrkl/outputParser.js +2 -2
  35. package/dist/agents/structured_chat/index.cjs +106 -0
  36. package/dist/agents/structured_chat/index.d.ts +44 -0
  37. package/dist/agents/structured_chat/index.js +102 -0
  38. package/dist/agents/structured_chat/outputParser.cjs +92 -0
  39. package/dist/agents/structured_chat/outputParser.d.ts +24 -0
  40. package/dist/agents/structured_chat/outputParser.js +87 -0
  41. package/dist/agents/structured_chat/prompt.cjs +62 -0
  42. package/dist/agents/structured_chat/prompt.d.ts +4 -0
  43. package/dist/agents/structured_chat/prompt.js +59 -0
  44. package/dist/callbacks/handlers/tracer_langchain.cjs +12 -4
  45. package/dist/callbacks/handlers/tracer_langchain.d.ts +4 -1
  46. package/dist/callbacks/handlers/tracer_langchain.js +12 -4
  47. package/dist/callbacks/manager.cjs +6 -2
  48. package/dist/callbacks/manager.js +6 -2
  49. package/dist/chains/query_constructor/index.cjs +105 -0
  50. package/dist/chains/query_constructor/index.d.ts +37 -0
  51. package/dist/chains/query_constructor/index.js +95 -0
  52. package/dist/chains/query_constructor/ir.cjs +116 -0
  53. package/dist/chains/query_constructor/ir.d.ts +60 -0
  54. package/dist/chains/query_constructor/ir.js +107 -0
  55. package/dist/chains/query_constructor/parser.cjs +103 -0
  56. package/dist/chains/query_constructor/parser.d.ts +12 -0
  57. package/dist/chains/query_constructor/parser.js +99 -0
  58. package/dist/chains/query_constructor/prompt.cjs +127 -0
  59. package/dist/chains/query_constructor/prompt.d.ts +15 -0
  60. package/dist/chains/query_constructor/prompt.js +124 -0
  61. package/dist/chains/sql_db/sql_db_chain.cjs +13 -0
  62. package/dist/chains/sql_db/sql_db_chain.d.ts +2 -0
  63. package/dist/chains/sql_db/sql_db_chain.js +13 -0
  64. package/dist/client/langchainplus.cjs +21 -15
  65. package/dist/client/langchainplus.d.ts +4 -2
  66. package/dist/client/langchainplus.js +21 -15
  67. package/dist/llms/sagemaker_endpoint.cjs +123 -0
  68. package/dist/llms/sagemaker_endpoint.d.ts +82 -0
  69. package/dist/llms/sagemaker_endpoint.js +118 -0
  70. package/dist/memory/buffer_memory.cjs +1 -1
  71. package/dist/memory/buffer_memory.js +1 -1
  72. package/dist/memory/buffer_window_memory.cjs +1 -1
  73. package/dist/memory/buffer_window_memory.js +1 -1
  74. package/dist/output_parsers/expression.cjs +68 -0
  75. package/dist/output_parsers/expression.d.ts +25 -0
  76. package/dist/output_parsers/expression.js +49 -0
  77. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.cjs +26 -0
  78. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.d.ts +7 -0
  79. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.js +22 -0
  80. package/dist/output_parsers/expression_type_handlers/base.cjs +67 -0
  81. package/dist/output_parsers/expression_type_handlers/base.d.ts +23 -0
  82. package/dist/output_parsers/expression_type_handlers/base.js +62 -0
  83. package/dist/output_parsers/expression_type_handlers/boolean_literal_handler.cjs +24 -0
  84. package/dist/output_parsers/expression_type_handlers/boolean_literal_handler.d.ts +7 -0
  85. package/dist/output_parsers/expression_type_handlers/boolean_literal_handler.js +20 -0
  86. package/dist/output_parsers/expression_type_handlers/call_expression_handler.cjs +52 -0
  87. package/dist/output_parsers/expression_type_handlers/call_expression_handler.d.ts +7 -0
  88. package/dist/output_parsers/expression_type_handlers/call_expression_handler.js +48 -0
  89. package/dist/output_parsers/expression_type_handlers/factory.cjs +56 -0
  90. package/dist/output_parsers/expression_type_handlers/factory.d.ts +9 -0
  91. package/dist/output_parsers/expression_type_handlers/factory.js +52 -0
  92. package/dist/output_parsers/expression_type_handlers/identifier_handler.cjs +22 -0
  93. package/dist/output_parsers/expression_type_handlers/identifier_handler.d.ts +7 -0
  94. package/dist/output_parsers/expression_type_handlers/identifier_handler.js +18 -0
  95. package/dist/output_parsers/expression_type_handlers/member_expression_handler.cjs +45 -0
  96. package/dist/output_parsers/expression_type_handlers/member_expression_handler.d.ts +7 -0
  97. package/dist/output_parsers/expression_type_handlers/member_expression_handler.js +41 -0
  98. package/dist/output_parsers/expression_type_handlers/numeric_literal_handler.cjs +24 -0
  99. package/dist/output_parsers/expression_type_handlers/numeric_literal_handler.d.ts +7 -0
  100. package/dist/output_parsers/expression_type_handlers/numeric_literal_handler.js +20 -0
  101. package/dist/output_parsers/expression_type_handlers/object_literal_expression_handler.cjs +29 -0
  102. package/dist/output_parsers/expression_type_handlers/object_literal_expression_handler.d.ts +7 -0
  103. package/dist/output_parsers/expression_type_handlers/object_literal_expression_handler.js +25 -0
  104. package/dist/output_parsers/expression_type_handlers/property_assignment_handler.cjs +36 -0
  105. package/dist/output_parsers/expression_type_handlers/property_assignment_handler.d.ts +7 -0
  106. package/dist/output_parsers/expression_type_handlers/property_assignment_handler.js +32 -0
  107. package/dist/output_parsers/expression_type_handlers/string_literal_handler.cjs +22 -0
  108. package/dist/output_parsers/expression_type_handlers/string_literal_handler.d.ts +7 -0
  109. package/dist/output_parsers/expression_type_handlers/string_literal_handler.js +18 -0
  110. package/dist/output_parsers/expression_type_handlers/types.cjs +2 -0
  111. package/dist/output_parsers/expression_type_handlers/types.d.ts +41 -0
  112. package/dist/output_parsers/expression_type_handlers/types.js +1 -0
  113. package/dist/output_parsers/index.cjs +2 -1
  114. package/dist/output_parsers/index.d.ts +1 -1
  115. package/dist/output_parsers/index.js +1 -1
  116. package/dist/output_parsers/structured.cjs +81 -23
  117. package/dist/output_parsers/structured.d.ts +18 -0
  118. package/dist/output_parsers/structured.js +79 -22
  119. package/dist/retrievers/self_query/index.cjs +79 -0
  120. package/dist/retrievers/self_query/index.d.ts +33 -0
  121. package/dist/retrievers/self_query/index.js +74 -0
  122. package/dist/retrievers/self_query/translator.cjs +72 -0
  123. package/dist/retrievers/self_query/translator.d.ts +14 -0
  124. package/dist/retrievers/self_query/translator.js +67 -0
  125. package/dist/schema/query_constructor.cjs +26 -0
  126. package/dist/schema/query_constructor.d.ts +6 -0
  127. package/dist/schema/query_constructor.js +22 -0
  128. package/dist/text_splitter.cjs +2 -1
  129. package/dist/text_splitter.js +2 -1
  130. package/dist/tools/dynamic.cjs +39 -1
  131. package/dist/tools/dynamic.d.ts +18 -3
  132. package/dist/tools/dynamic.js +38 -1
  133. package/dist/tools/index.cjs +2 -1
  134. package/dist/tools/index.d.ts +1 -1
  135. package/dist/tools/index.js +1 -1
  136. package/dist/tools/json.cjs +3 -1
  137. package/dist/tools/json.js +3 -1
  138. package/dist/tools/sql.cjs +17 -11
  139. package/dist/tools/sql.d.ts +7 -1
  140. package/dist/tools/sql.js +17 -11
  141. package/dist/util/event-source-parse.cjs +31 -5
  142. package/dist/util/event-source-parse.d.ts +3 -3
  143. package/dist/util/event-source-parse.js +31 -5
  144. package/dist/vectorstores/faiss.cjs +245 -0
  145. package/dist/vectorstores/faiss.d.ts +39 -0
  146. package/dist/vectorstores/faiss.js +218 -0
  147. package/llms/sagemaker_endpoint.cjs +1 -0
  148. package/llms/sagemaker_endpoint.d.ts +1 -0
  149. package/llms/sagemaker_endpoint.js +1 -0
  150. package/output_parsers/expression.cjs +1 -0
  151. package/output_parsers/expression.d.ts +1 -0
  152. package/output_parsers/expression.js +1 -0
  153. package/package.json +79 -3
  154. package/retrievers/self_query.cjs +1 -0
  155. package/retrievers/self_query.d.ts +1 -0
  156. package/retrievers/self_query.js +1 -0
  157. package/schema/query_constructor.cjs +1 -0
  158. package/schema/query_constructor.d.ts +1 -0
  159. package/schema/query_constructor.js +1 -0
  160. package/vectorstores/faiss.cjs +1 -0
  161. package/vectorstores/faiss.d.ts +1 -0
  162. package/vectorstores/faiss.js +1 -0
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SageMakerEndpoint = exports.BaseSageMakerContentHandler = void 0;
4
+ const client_sagemaker_runtime_1 = require("@aws-sdk/client-sagemaker-runtime");
5
+ const base_js_1 = require("./base.cjs");
6
+ /**
7
+ * A handler class to transform input from LLM to a format that SageMaker
8
+ * endpoint expects. Similarily, the class also handles transforming output from
9
+ * the SageMaker endpoint to a format that LLM class expects.
10
+ *
11
+ * Example:
12
+ * ```
13
+ * class ContentHandler implements ContentHandlerBase<string, string> {
14
+ * contentType = "application/json"
15
+ * accepts = "application/json"
16
+ *
17
+ * transformInput(prompt: string, modelKwargs: Record<string, unknown>) {
18
+ * const inputString = JSON.stringify({
19
+ * prompt,
20
+ * ...modelKwargs
21
+ * })
22
+ * return Buffer.from(inputString)
23
+ * }
24
+ *
25
+ * transformOutput(output: Uint8Array) {
26
+ * const responseJson = JSON.parse(Buffer.from(output).toString("utf-8"))
27
+ * return responseJson[0].generated_text
28
+ * }
29
+ *
30
+ * }
31
+ * ```
32
+ */
33
+ class BaseSageMakerContentHandler {
34
+ constructor() {
35
+ /** The MIME type of the input data passed to endpoint */
36
+ Object.defineProperty(this, "contentType", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: "text/plain"
41
+ });
42
+ /** The MIME type of the response data returned from endpoint */
43
+ Object.defineProperty(this, "accepts", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: "text/plain"
48
+ });
49
+ }
50
+ }
51
+ exports.BaseSageMakerContentHandler = BaseSageMakerContentHandler;
52
+ class SageMakerEndpoint extends base_js_1.LLM {
53
+ constructor(fields) {
54
+ super(fields ?? {});
55
+ Object.defineProperty(this, "endpointName", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: void 0
60
+ });
61
+ Object.defineProperty(this, "contentHandler", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: void 0
66
+ });
67
+ Object.defineProperty(this, "modelKwargs", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: void 0
72
+ });
73
+ Object.defineProperty(this, "endpointKwargs", {
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true,
77
+ value: void 0
78
+ });
79
+ Object.defineProperty(this, "client", {
80
+ enumerable: true,
81
+ configurable: true,
82
+ writable: true,
83
+ value: void 0
84
+ });
85
+ const regionName = fields.clientOptions.region;
86
+ if (!regionName) {
87
+ throw new Error(`Please pass a "clientOptions" object with a "region" field to the constructor`);
88
+ }
89
+ const endpointName = fields?.endpointName;
90
+ if (!endpointName) {
91
+ throw new Error(`Please pass an "endpointName" field to the constructor`);
92
+ }
93
+ const contentHandler = fields?.contentHandler;
94
+ if (!contentHandler) {
95
+ throw new Error(`Please pass a "contentHandler" field to the constructor`);
96
+ }
97
+ this.endpointName = fields.endpointName;
98
+ this.contentHandler = fields.contentHandler;
99
+ this.endpointKwargs = fields.endpointKwargs;
100
+ this.modelKwargs = fields.modelKwargs;
101
+ this.client = new client_sagemaker_runtime_1.SageMakerRuntimeClient(fields.clientOptions);
102
+ }
103
+ _llmType() {
104
+ return "sagemaker_endpoint";
105
+ }
106
+ /** @ignore */
107
+ async _call(prompt, options) {
108
+ const body = await this.contentHandler.transformInput(prompt, this.modelKwargs ?? {});
109
+ const { contentType, accepts } = this.contentHandler;
110
+ const response = await this.caller.call(() => this.client.send(new client_sagemaker_runtime_1.InvokeEndpointCommand({
111
+ EndpointName: this.endpointName,
112
+ Body: body,
113
+ ContentType: contentType,
114
+ Accept: accepts,
115
+ ...this.endpointKwargs,
116
+ }), { abortSignal: options.signal }));
117
+ if (response.Body === undefined) {
118
+ throw new Error("Inference result missing Body");
119
+ }
120
+ return this.contentHandler.transformOutput(response.Body);
121
+ }
122
+ }
123
+ exports.SageMakerEndpoint = SageMakerEndpoint;
@@ -0,0 +1,82 @@
1
+ import { SageMakerRuntimeClient, SageMakerRuntimeClientConfig } from "@aws-sdk/client-sagemaker-runtime";
2
+ import { LLM, BaseLLMParams } from "./base.js";
3
+ /**
4
+ * A handler class to transform input from LLM to a format that SageMaker
5
+ * endpoint expects. Similarily, the class also handles transforming output from
6
+ * the SageMaker endpoint to a format that LLM class expects.
7
+ *
8
+ * Example:
9
+ * ```
10
+ * class ContentHandler implements ContentHandlerBase<string, string> {
11
+ * contentType = "application/json"
12
+ * accepts = "application/json"
13
+ *
14
+ * transformInput(prompt: string, modelKwargs: Record<string, unknown>) {
15
+ * const inputString = JSON.stringify({
16
+ * prompt,
17
+ * ...modelKwargs
18
+ * })
19
+ * return Buffer.from(inputString)
20
+ * }
21
+ *
22
+ * transformOutput(output: Uint8Array) {
23
+ * const responseJson = JSON.parse(Buffer.from(output).toString("utf-8"))
24
+ * return responseJson[0].generated_text
25
+ * }
26
+ *
27
+ * }
28
+ * ```
29
+ */
30
+ export declare abstract class BaseSageMakerContentHandler<InputType, OutputType> {
31
+ /** The MIME type of the input data passed to endpoint */
32
+ contentType: string;
33
+ /** The MIME type of the response data returned from endpoint */
34
+ accepts: string;
35
+ /**
36
+ * Transforms the input to a format that model can accept as the request Body.
37
+ * Should return bytes or seekable file like object in the format specified in
38
+ * the contentType request header.
39
+ */
40
+ abstract transformInput(prompt: InputType, modelKwargs: Record<string, unknown>): Promise<Uint8Array>;
41
+ /**
42
+ * Transforms the output from the model to string that the LLM class expects.
43
+ */
44
+ abstract transformOutput(output: Uint8Array): Promise<OutputType>;
45
+ }
46
+ /** Content handler for LLM class. */
47
+ export type SageMakerLLMContentHandler = BaseSageMakerContentHandler<string, string>;
48
+ export interface SageMakerEndpointInput extends BaseLLMParams {
49
+ /**
50
+ * The name of the endpoint from the deployed SageMaker model. Must be unique
51
+ * within an AWS Region.
52
+ */
53
+ endpointName: string;
54
+ /**
55
+ * Options passed to the SageMaker client.
56
+ */
57
+ clientOptions: SageMakerRuntimeClientConfig;
58
+ /**
59
+ * The content handler class that provides an input and output transform
60
+ * functions to handle formats between LLM and the endpoint.
61
+ */
62
+ contentHandler: SageMakerLLMContentHandler;
63
+ /**
64
+ * Key word arguments to pass to the model.
65
+ */
66
+ modelKwargs?: Record<string, unknown>;
67
+ /**
68
+ * Optional attributes passed to the InvokeEndpointCommand
69
+ */
70
+ endpointKwargs?: Record<string, unknown>;
71
+ }
72
+ export declare class SageMakerEndpoint extends LLM {
73
+ endpointName: string;
74
+ contentHandler: SageMakerLLMContentHandler;
75
+ modelKwargs?: Record<string, unknown>;
76
+ endpointKwargs?: Record<string, unknown>;
77
+ client: SageMakerRuntimeClient;
78
+ constructor(fields: SageMakerEndpointInput);
79
+ _llmType(): string;
80
+ /** @ignore */
81
+ _call(prompt: string, options: this["ParsedCallOptions"]): Promise<string>;
82
+ }
@@ -0,0 +1,118 @@
1
+ import { SageMakerRuntimeClient, InvokeEndpointCommand, } from "@aws-sdk/client-sagemaker-runtime";
2
+ import { LLM } from "./base.js";
3
+ /**
4
+ * A handler class to transform input from LLM to a format that SageMaker
5
+ * endpoint expects. Similarily, the class also handles transforming output from
6
+ * the SageMaker endpoint to a format that LLM class expects.
7
+ *
8
+ * Example:
9
+ * ```
10
+ * class ContentHandler implements ContentHandlerBase<string, string> {
11
+ * contentType = "application/json"
12
+ * accepts = "application/json"
13
+ *
14
+ * transformInput(prompt: string, modelKwargs: Record<string, unknown>) {
15
+ * const inputString = JSON.stringify({
16
+ * prompt,
17
+ * ...modelKwargs
18
+ * })
19
+ * return Buffer.from(inputString)
20
+ * }
21
+ *
22
+ * transformOutput(output: Uint8Array) {
23
+ * const responseJson = JSON.parse(Buffer.from(output).toString("utf-8"))
24
+ * return responseJson[0].generated_text
25
+ * }
26
+ *
27
+ * }
28
+ * ```
29
+ */
30
+ export class BaseSageMakerContentHandler {
31
+ constructor() {
32
+ /** The MIME type of the input data passed to endpoint */
33
+ Object.defineProperty(this, "contentType", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: "text/plain"
38
+ });
39
+ /** The MIME type of the response data returned from endpoint */
40
+ Object.defineProperty(this, "accepts", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: "text/plain"
45
+ });
46
+ }
47
+ }
48
+ export class SageMakerEndpoint extends LLM {
49
+ constructor(fields) {
50
+ super(fields ?? {});
51
+ Object.defineProperty(this, "endpointName", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ Object.defineProperty(this, "contentHandler", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
63
+ Object.defineProperty(this, "modelKwargs", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ Object.defineProperty(this, "endpointKwargs", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: void 0
74
+ });
75
+ Object.defineProperty(this, "client", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: void 0
80
+ });
81
+ const regionName = fields.clientOptions.region;
82
+ if (!regionName) {
83
+ throw new Error(`Please pass a "clientOptions" object with a "region" field to the constructor`);
84
+ }
85
+ const endpointName = fields?.endpointName;
86
+ if (!endpointName) {
87
+ throw new Error(`Please pass an "endpointName" field to the constructor`);
88
+ }
89
+ const contentHandler = fields?.contentHandler;
90
+ if (!contentHandler) {
91
+ throw new Error(`Please pass a "contentHandler" field to the constructor`);
92
+ }
93
+ this.endpointName = fields.endpointName;
94
+ this.contentHandler = fields.contentHandler;
95
+ this.endpointKwargs = fields.endpointKwargs;
96
+ this.modelKwargs = fields.modelKwargs;
97
+ this.client = new SageMakerRuntimeClient(fields.clientOptions);
98
+ }
99
+ _llmType() {
100
+ return "sagemaker_endpoint";
101
+ }
102
+ /** @ignore */
103
+ async _call(prompt, options) {
104
+ const body = await this.contentHandler.transformInput(prompt, this.modelKwargs ?? {});
105
+ const { contentType, accepts } = this.contentHandler;
106
+ const response = await this.caller.call(() => this.client.send(new InvokeEndpointCommand({
107
+ EndpointName: this.endpointName,
108
+ Body: body,
109
+ ContentType: contentType,
110
+ Accept: accepts,
111
+ ...this.endpointKwargs,
112
+ }), { abortSignal: options.signal }));
113
+ if (response.Body === undefined) {
114
+ throw new Error("Inference result missing Body");
115
+ }
116
+ return this.contentHandler.transformOutput(response.Body);
117
+ }
118
+ }
@@ -45,7 +45,7 @@ class BufferMemory extends chat_memory_js_1.BaseChatMemory {
45
45
  return result;
46
46
  }
47
47
  const result = {
48
- [this.memoryKey]: (0, base_js_1.getBufferString)(messages),
48
+ [this.memoryKey]: (0, base_js_1.getBufferString)(messages, this.humanPrefix, this.aiPrefix),
49
49
  };
50
50
  return result;
51
51
  }
@@ -42,7 +42,7 @@ export class BufferMemory extends BaseChatMemory {
42
42
  return result;
43
43
  }
44
44
  const result = {
45
- [this.memoryKey]: getBufferString(messages),
45
+ [this.memoryKey]: getBufferString(messages, this.humanPrefix, this.aiPrefix),
46
46
  };
47
47
  return result;
48
48
  }
@@ -52,7 +52,7 @@ class BufferWindowMemory extends chat_memory_js_1.BaseChatMemory {
52
52
  return result;
53
53
  }
54
54
  const result = {
55
- [this.memoryKey]: (0, base_js_1.getBufferString)(messages.slice(-this.k * 2)),
55
+ [this.memoryKey]: (0, base_js_1.getBufferString)(messages.slice(-this.k * 2), this.humanPrefix, this.aiPrefix),
56
56
  };
57
57
  return result;
58
58
  }
@@ -49,7 +49,7 @@ export class BufferWindowMemory extends BaseChatMemory {
49
49
  return result;
50
50
  }
51
51
  const result = {
52
- [this.memoryKey]: getBufferString(messages.slice(-this.k * 2)),
52
+ [this.memoryKey]: getBufferString(messages.slice(-this.k * 2), this.humanPrefix, this.aiPrefix),
53
53
  };
54
54
  return result;
55
55
  }
@@ -0,0 +1,68 @@
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
+ exports.MasterHandler = exports.ExpressionParser = void 0;
18
+ const factory_js_1 = require("./expression_type_handlers/factory.cjs");
19
+ const output_parser_js_1 = require("../schema/output_parser.cjs");
20
+ const base_js_1 = require("./expression_type_handlers/base.cjs");
21
+ /**
22
+ * okay so we need to be able to handle the following cases:
23
+ * ExpressionStatement
24
+ * CallExpression
25
+ * Identifier | MemberExpression
26
+ * ExpressionLiterals: [
27
+ * CallExpression
28
+ * StringLiteral
29
+ * NumericLiteral
30
+ * ArrayLiteralExpression
31
+ * ExpressionLiterals
32
+ * ObjectLiteralExpression
33
+ * PropertyAssignment
34
+ * Identifier
35
+ * ExpressionLiterals
36
+ * ]
37
+ */
38
+ class ExpressionParser extends output_parser_js_1.BaseOutputParser {
39
+ async parse(text) {
40
+ const parse = await base_js_1.ASTParser.importASTParser();
41
+ try {
42
+ const program = parse(text);
43
+ if (program.body.length > 1) {
44
+ throw new Error(`Expected 1 statement, got ${program.body.length}`);
45
+ }
46
+ const [node] = program.body;
47
+ if (!base_js_1.ASTParser.isExpressionStatement(node)) {
48
+ throw new Error(`Expected ExpressionStatement, got ${node.type}`);
49
+ }
50
+ const { expression: expressionStatement } = node;
51
+ if (!base_js_1.ASTParser.isCallExpression(expressionStatement)) {
52
+ throw new Error("Expected CallExpression");
53
+ }
54
+ const masterHandler = factory_js_1.MasterHandler.createMasterHandler();
55
+ return await masterHandler.handle(expressionStatement);
56
+ }
57
+ catch (err) {
58
+ throw new Error(`Error parsing ${err}: ${text}`);
59
+ }
60
+ }
61
+ getFormatInstructions() {
62
+ return "";
63
+ }
64
+ }
65
+ exports.ExpressionParser = ExpressionParser;
66
+ __exportStar(require("./expression_type_handlers/types.cjs"), exports);
67
+ var factory_js_2 = require("./expression_type_handlers/factory.cjs");
68
+ Object.defineProperty(exports, "MasterHandler", { enumerable: true, get: function () { return factory_js_2.MasterHandler; } });
@@ -0,0 +1,25 @@
1
+ import { ParsedType } from "./expression_type_handlers/types.js";
2
+ import { BaseOutputParser } from "../schema/output_parser.js";
3
+ /**
4
+ * okay so we need to be able to handle the following cases:
5
+ * ExpressionStatement
6
+ * CallExpression
7
+ * Identifier | MemberExpression
8
+ * ExpressionLiterals: [
9
+ * CallExpression
10
+ * StringLiteral
11
+ * NumericLiteral
12
+ * ArrayLiteralExpression
13
+ * ExpressionLiterals
14
+ * ObjectLiteralExpression
15
+ * PropertyAssignment
16
+ * Identifier
17
+ * ExpressionLiterals
18
+ * ]
19
+ */
20
+ export declare class ExpressionParser extends BaseOutputParser<ParsedType> {
21
+ parse(text: string): Promise<ParsedType>;
22
+ getFormatInstructions(): string;
23
+ }
24
+ export * from "./expression_type_handlers/types.js";
25
+ export { MasterHandler } from "./expression_type_handlers/factory.js";
@@ -0,0 +1,49 @@
1
+ import { MasterHandler } from "./expression_type_handlers/factory.js";
2
+ import { BaseOutputParser } from "../schema/output_parser.js";
3
+ import { ASTParser } from "./expression_type_handlers/base.js";
4
+ /**
5
+ * okay so we need to be able to handle the following cases:
6
+ * ExpressionStatement
7
+ * CallExpression
8
+ * Identifier | MemberExpression
9
+ * ExpressionLiterals: [
10
+ * CallExpression
11
+ * StringLiteral
12
+ * NumericLiteral
13
+ * ArrayLiteralExpression
14
+ * ExpressionLiterals
15
+ * ObjectLiteralExpression
16
+ * PropertyAssignment
17
+ * Identifier
18
+ * ExpressionLiterals
19
+ * ]
20
+ */
21
+ export class ExpressionParser extends BaseOutputParser {
22
+ async parse(text) {
23
+ const parse = await ASTParser.importASTParser();
24
+ try {
25
+ const program = parse(text);
26
+ if (program.body.length > 1) {
27
+ throw new Error(`Expected 1 statement, got ${program.body.length}`);
28
+ }
29
+ const [node] = program.body;
30
+ if (!ASTParser.isExpressionStatement(node)) {
31
+ throw new Error(`Expected ExpressionStatement, got ${node.type}`);
32
+ }
33
+ const { expression: expressionStatement } = node;
34
+ if (!ASTParser.isCallExpression(expressionStatement)) {
35
+ throw new Error("Expected CallExpression");
36
+ }
37
+ const masterHandler = MasterHandler.createMasterHandler();
38
+ return await masterHandler.handle(expressionStatement);
39
+ }
40
+ catch (err) {
41
+ throw new Error(`Error parsing ${err}: ${text}`);
42
+ }
43
+ }
44
+ getFormatInstructions() {
45
+ return "";
46
+ }
47
+ }
48
+ export * from "./expression_type_handlers/types.js";
49
+ export { MasterHandler } from "./expression_type_handlers/factory.js";
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArrayLiteralExpressionHandler = void 0;
4
+ const base_js_1 = require("./base.cjs");
5
+ class ArrayLiteralExpressionHandler extends base_js_1.NodeHandler {
6
+ async accepts(node) {
7
+ if (base_js_1.ASTParser.isArrayExpression(node)) {
8
+ return node;
9
+ }
10
+ else {
11
+ return false;
12
+ }
13
+ }
14
+ async handle(node) {
15
+ if (!this.parentHandler) {
16
+ throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
17
+ }
18
+ return {
19
+ type: "array_literal",
20
+ values: await Promise.all(node.elements.map((innerNode) =>
21
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
+ this.parentHandler.handle(innerNode))),
23
+ };
24
+ }
25
+ }
26
+ exports.ArrayLiteralExpressionHandler = ArrayLiteralExpressionHandler;
@@ -0,0 +1,7 @@
1
+ import type { ESTree } from "meriyah";
2
+ import { NodeHandler } from "./base.js";
3
+ import { ArrayLiteralType } from "./types.js";
4
+ export declare class ArrayLiteralExpressionHandler extends NodeHandler {
5
+ accepts(node: ESTree.Node): Promise<ESTree.ArrayExpression | boolean>;
6
+ handle(node: ESTree.ArrayExpression): Promise<ArrayLiteralType>;
7
+ }
@@ -0,0 +1,22 @@
1
+ import { NodeHandler, ASTParser } from "./base.js";
2
+ export class ArrayLiteralExpressionHandler extends NodeHandler {
3
+ async accepts(node) {
4
+ if (ASTParser.isArrayExpression(node)) {
5
+ return node;
6
+ }
7
+ else {
8
+ return false;
9
+ }
10
+ }
11
+ async handle(node) {
12
+ if (!this.parentHandler) {
13
+ throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
14
+ }
15
+ return {
16
+ type: "array_literal",
17
+ values: await Promise.all(node.elements.map((innerNode) =>
18
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19
+ this.parentHandler.handle(innerNode))),
20
+ };
21
+ }
22
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ASTParser = exports.NodeHandler = void 0;
4
+ class NodeHandler {
5
+ constructor(parentHandler) {
6
+ Object.defineProperty(this, "parentHandler", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: parentHandler
11
+ });
12
+ }
13
+ }
14
+ exports.NodeHandler = NodeHandler;
15
+ class ASTParser {
16
+ static async importASTParser() {
17
+ try {
18
+ if (!ASTParser.astParseInstance) {
19
+ const meriyah = await import("meriyah");
20
+ ASTParser.astParseInstance =
21
+ meriyah.parseScript;
22
+ }
23
+ return ASTParser.astParseInstance;
24
+ }
25
+ catch (e) {
26
+ console.log(e);
27
+ throw new Error("Failed to import meriyah. Please install meriyah (i.e. npm install meriyah).");
28
+ }
29
+ }
30
+ static isProgram(node) {
31
+ return node.type === "Program";
32
+ }
33
+ static isExpressionStatement(node) {
34
+ return node.type === "ExpressionStatement";
35
+ }
36
+ static isCallExpression(node) {
37
+ return node.type === "CallExpression";
38
+ }
39
+ static isLiteral(node) {
40
+ return node.type === "Literal";
41
+ }
42
+ static isStringLiteral(node) {
43
+ return node.type === "Literal" && typeof node.value === "string";
44
+ }
45
+ static isNumericLiteral(node) {
46
+ return node.type === "Literal" && typeof node.value === "number";
47
+ }
48
+ static isBooleanLiteral(node) {
49
+ return node.type === "Literal" && typeof node.value === "boolean";
50
+ }
51
+ static isIdentifier(node) {
52
+ return node.type === "Identifier";
53
+ }
54
+ static isObjectExpression(node) {
55
+ return node.type === "ObjectExpression";
56
+ }
57
+ static isArrayExpression(node) {
58
+ return node.type === "ArrayExpression";
59
+ }
60
+ static isProperty(node) {
61
+ return node.type === "Property";
62
+ }
63
+ static isMemberExpression(node) {
64
+ return node.type === "MemberExpression";
65
+ }
66
+ }
67
+ exports.ASTParser = ASTParser;
@@ -0,0 +1,23 @@
1
+ import type meriyahT from "meriyah";
2
+ export declare abstract class NodeHandler {
3
+ protected parentHandler?: NodeHandler | undefined;
4
+ constructor(parentHandler?: NodeHandler | undefined);
5
+ abstract accepts(node: meriyahT.ESTree.Node): Promise<meriyahT.ESTree.Node | boolean>;
6
+ abstract handle(node: meriyahT.ESTree.Node): Promise<any>;
7
+ }
8
+ export declare class ASTParser {
9
+ static astParseInstance: typeof meriyahT.parseScript;
10
+ static importASTParser(): Promise<typeof meriyahT.parseScript>;
11
+ static isProgram(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.Program;
12
+ static isExpressionStatement(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.ExpressionStatement;
13
+ static isCallExpression(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.CallExpression;
14
+ static isLiteral(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.Literal;
15
+ static isStringLiteral(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.Literal;
16
+ static isNumericLiteral(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.Literal;
17
+ static isBooleanLiteral(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.Literal;
18
+ static isIdentifier(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.Identifier;
19
+ static isObjectExpression(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.ObjectExpression;
20
+ static isArrayExpression(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.ArrayExpression;
21
+ static isProperty(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.Property;
22
+ static isMemberExpression(node: meriyahT.ESTree.Node): node is meriyahT.ESTree.MemberExpression;
23
+ }