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,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SUFFIX = exports.DEFAULT_PREFIX = exports.DEFAULT_SCHEMA = exports.EXAMPLE_PROMPT = exports.EXAMPLE_PROMPT_TEMPLATE = exports.DEFAULT_EXAMPLES = exports.NO_FILTER_ANSWER = exports.FULL_ANSWER = exports.SONG_DATA_SOURCE = void 0;
4
+ const prompt_js_1 = require("../../prompts/prompt.cjs");
5
+ exports.SONG_DATA_SOURCE = `\
6
+ \`\`\`json
7
+ {
8
+ content: "Lyrics of a song",
9
+ attributes: {
10
+ "artist": {
11
+ "type": "string",
12
+ "description": "Name of the song artist"
13
+ },
14
+ "length": {
15
+ "type": "integer",
16
+ "description": "Length of the song in seconds"
17
+ },
18
+ "genre": {
19
+ "type": "string",
20
+ "description": "The song genre, one of 'pop', 'rock' or 'rap'"
21
+ }
22
+ }
23
+ }
24
+ \`\`\`\
25
+ `
26
+ .replaceAll("{", "{{")
27
+ .replaceAll("}", "}}");
28
+ exports.FULL_ANSWER = `\
29
+ \`\`\`json
30
+ {{
31
+ "query": "teenager love",
32
+ "filter": "and(or(eq(\\"artist\\", \\"Taylor Swift\\"), eq(\\"artist\\", \\"Katy Perry\\")), \
33
+ lt(\\"length\\", 180), eq(\\"genre\\", \\"pop\\"))"
34
+ }}`;
35
+ exports.NO_FILTER_ANSWER = `\
36
+ \`\`\`json
37
+ {{
38
+ "query": "",
39
+ "filter": "NO_FILTER"
40
+ }}
41
+ \`\`\`\
42
+ `;
43
+ exports.DEFAULT_EXAMPLES = [
44
+ {
45
+ i: "1",
46
+ data_source: exports.SONG_DATA_SOURCE,
47
+ user_query: "What are songs by Taylor Swift or Katy Perry about teenage romance under 3 minutes long in the dance pop genre",
48
+ structured_request: exports.FULL_ANSWER,
49
+ },
50
+ {
51
+ i: "2",
52
+ data_source: exports.SONG_DATA_SOURCE,
53
+ user_query: "What are songs that were not published on Spotify",
54
+ structured_request: exports.NO_FILTER_ANSWER,
55
+ },
56
+ ];
57
+ exports.EXAMPLE_PROMPT_TEMPLATE = `\
58
+ << Example {i}. >>
59
+ Data Source:
60
+ {data_source}
61
+
62
+ User Query:
63
+ {user_query}
64
+
65
+ Structured Request:
66
+ {structured_request}
67
+ `;
68
+ exports.EXAMPLE_PROMPT = new prompt_js_1.PromptTemplate({
69
+ inputVariables: ["i", "data_source", "user_query", "structured_request"],
70
+ template: exports.EXAMPLE_PROMPT_TEMPLATE,
71
+ });
72
+ exports.DEFAULT_SCHEMA = `\
73
+ << Structured Request Schema >>
74
+ When responding use a markdown code snippet with a JSON object formatted in the \
75
+ following schema:
76
+
77
+ \`\`\`json
78
+ {{{{
79
+ "query": string \\ text string to compare to document contents
80
+ "filter": string \\ logical condition statement for filtering documents
81
+ }}}}
82
+ \`\`\`
83
+
84
+ The query string should contain only text that is expected to match the contents of \
85
+ documents. Any conditions in the filter should not be mentioned in the query as well.
86
+
87
+ A logical condition statement is composed of one or more comparison and logical \
88
+ operation statements.
89
+
90
+ A comparison statement takes the form: \`comp(attr, val)\`:
91
+ - \`comp\` ({allowed_comparators}): comparator
92
+ - \`attr\` (string): name of attribute to apply the comparison to
93
+ - \`val\` (string): is the comparison value
94
+
95
+ A logical operation statement takes the form \`op(statement1, statement2, ...)\`:
96
+ - \`op\` ({allowed_operators}): logical operator
97
+ - \`statement1\`, \`statement2\`, ... (comparison statements or logical operation \
98
+ statements): one or more statements to appy the operation to
99
+
100
+ Make sure that you only use the comparators and logical operators listed above and \
101
+ no others.
102
+ Make sure that filters only refer to attributes that exist in the data source.
103
+ Make sure that filters take into account the descriptions of attributes and only make \
104
+ comparisons that are feasible given the type of data being stored.
105
+ Make sure that filters are only used as needed. If there are no filters that should be \
106
+ applied return "NO_FILTER" for the filter value.\
107
+ `;
108
+ exports.DEFAULT_PREFIX = `\
109
+ Your goal is to structure the user's query to match the request schema provided below.
110
+
111
+ {schema}\
112
+ `;
113
+ exports.DEFAULT_SUFFIX = `\
114
+ << Example {i}. >>
115
+ Data Source:
116
+ \`\`\`json
117
+ {{{{
118
+ content: {content},
119
+ attributes: {attributes}
120
+ }}}}
121
+ \`\`\`
122
+
123
+ User Query:
124
+ {{query}}
125
+
126
+ Structured Request:
127
+ `;
@@ -0,0 +1,15 @@
1
+ import { PromptTemplate } from "../../prompts/prompt.js";
2
+ export declare const SONG_DATA_SOURCE: string;
3
+ export declare const FULL_ANSWER = "```json\n{{\n \"query\": \"teenager love\",\n \"filter\": \"and(or(eq(\\\"artist\\\", \\\"Taylor Swift\\\"), eq(\\\"artist\\\", \\\"Katy Perry\\\")), lt(\\\"length\\\", 180), eq(\\\"genre\\\", \\\"pop\\\"))\"\n}}";
4
+ export declare const NO_FILTER_ANSWER = "```json\n{{\n \"query\": \"\",\n \"filter\": \"NO_FILTER\"\n}}\n```";
5
+ export declare const DEFAULT_EXAMPLES: {
6
+ i: string;
7
+ data_source: string;
8
+ user_query: string;
9
+ structured_request: string;
10
+ }[];
11
+ export declare const EXAMPLE_PROMPT_TEMPLATE = "<< Example {i}. >>\nData Source:\n{data_source}\n\nUser Query:\n{user_query}\n\nStructured Request:\n{structured_request}\n";
12
+ export declare const EXAMPLE_PROMPT: PromptTemplate;
13
+ export declare const DEFAULT_SCHEMA = "<< Structured Request Schema >>\nWhen responding use a markdown code snippet with a JSON object formatted in the following schema:\n\n```json\n{{{{\n \"query\": string \\ text string to compare to document contents\n \"filter\": string \\ logical condition statement for filtering documents\n}}}}\n```\n\nThe query string should contain only text that is expected to match the contents of documents. Any conditions in the filter should not be mentioned in the query as well.\n\nA logical condition statement is composed of one or more comparison and logical operation statements.\n\nA comparison statement takes the form: `comp(attr, val)`:\n- `comp` ({allowed_comparators}): comparator\n- `attr` (string): name of attribute to apply the comparison to\n- `val` (string): is the comparison value\n\nA logical operation statement takes the form `op(statement1, statement2, ...)`:\n- `op` ({allowed_operators}): logical operator\n- `statement1`, `statement2`, ... (comparison statements or logical operation statements): one or more statements to appy the operation to\n\nMake sure that you only use the comparators and logical operators listed above and no others.\nMake sure that filters only refer to attributes that exist in the data source.\nMake sure that filters take into account the descriptions of attributes and only make comparisons that are feasible given the type of data being stored.\nMake sure that filters are only used as needed. If there are no filters that should be applied return \"NO_FILTER\" for the filter value.";
14
+ export declare const DEFAULT_PREFIX = "Your goal is to structure the user's query to match the request schema provided below.\n\n{schema}";
15
+ export declare const DEFAULT_SUFFIX = "<< Example {i}. >>\nData Source:\n```json\n{{{{\n content: {content},\n attributes: {attributes}\n}}}}\n```\n\nUser Query:\n{{query}}\n\nStructured Request:\n";
@@ -0,0 +1,124 @@
1
+ import { PromptTemplate } from "../../prompts/prompt.js";
2
+ export const SONG_DATA_SOURCE = `\
3
+ \`\`\`json
4
+ {
5
+ content: "Lyrics of a song",
6
+ attributes: {
7
+ "artist": {
8
+ "type": "string",
9
+ "description": "Name of the song artist"
10
+ },
11
+ "length": {
12
+ "type": "integer",
13
+ "description": "Length of the song in seconds"
14
+ },
15
+ "genre": {
16
+ "type": "string",
17
+ "description": "The song genre, one of 'pop', 'rock' or 'rap'"
18
+ }
19
+ }
20
+ }
21
+ \`\`\`\
22
+ `
23
+ .replaceAll("{", "{{")
24
+ .replaceAll("}", "}}");
25
+ export const FULL_ANSWER = `\
26
+ \`\`\`json
27
+ {{
28
+ "query": "teenager love",
29
+ "filter": "and(or(eq(\\"artist\\", \\"Taylor Swift\\"), eq(\\"artist\\", \\"Katy Perry\\")), \
30
+ lt(\\"length\\", 180), eq(\\"genre\\", \\"pop\\"))"
31
+ }}`;
32
+ export const NO_FILTER_ANSWER = `\
33
+ \`\`\`json
34
+ {{
35
+ "query": "",
36
+ "filter": "NO_FILTER"
37
+ }}
38
+ \`\`\`\
39
+ `;
40
+ export const DEFAULT_EXAMPLES = [
41
+ {
42
+ i: "1",
43
+ data_source: SONG_DATA_SOURCE,
44
+ user_query: "What are songs by Taylor Swift or Katy Perry about teenage romance under 3 minutes long in the dance pop genre",
45
+ structured_request: FULL_ANSWER,
46
+ },
47
+ {
48
+ i: "2",
49
+ data_source: SONG_DATA_SOURCE,
50
+ user_query: "What are songs that were not published on Spotify",
51
+ structured_request: NO_FILTER_ANSWER,
52
+ },
53
+ ];
54
+ export const EXAMPLE_PROMPT_TEMPLATE = `\
55
+ << Example {i}. >>
56
+ Data Source:
57
+ {data_source}
58
+
59
+ User Query:
60
+ {user_query}
61
+
62
+ Structured Request:
63
+ {structured_request}
64
+ `;
65
+ export const EXAMPLE_PROMPT = /* #__PURE__ */ new PromptTemplate({
66
+ inputVariables: ["i", "data_source", "user_query", "structured_request"],
67
+ template: EXAMPLE_PROMPT_TEMPLATE,
68
+ });
69
+ export const DEFAULT_SCHEMA = `\
70
+ << Structured Request Schema >>
71
+ When responding use a markdown code snippet with a JSON object formatted in the \
72
+ following schema:
73
+
74
+ \`\`\`json
75
+ {{{{
76
+ "query": string \\ text string to compare to document contents
77
+ "filter": string \\ logical condition statement for filtering documents
78
+ }}}}
79
+ \`\`\`
80
+
81
+ The query string should contain only text that is expected to match the contents of \
82
+ documents. Any conditions in the filter should not be mentioned in the query as well.
83
+
84
+ A logical condition statement is composed of one or more comparison and logical \
85
+ operation statements.
86
+
87
+ A comparison statement takes the form: \`comp(attr, val)\`:
88
+ - \`comp\` ({allowed_comparators}): comparator
89
+ - \`attr\` (string): name of attribute to apply the comparison to
90
+ - \`val\` (string): is the comparison value
91
+
92
+ A logical operation statement takes the form \`op(statement1, statement2, ...)\`:
93
+ - \`op\` ({allowed_operators}): logical operator
94
+ - \`statement1\`, \`statement2\`, ... (comparison statements or logical operation \
95
+ statements): one or more statements to appy the operation to
96
+
97
+ Make sure that you only use the comparators and logical operators listed above and \
98
+ no others.
99
+ Make sure that filters only refer to attributes that exist in the data source.
100
+ Make sure that filters take into account the descriptions of attributes and only make \
101
+ comparisons that are feasible given the type of data being stored.
102
+ Make sure that filters are only used as needed. If there are no filters that should be \
103
+ applied return "NO_FILTER" for the filter value.\
104
+ `;
105
+ export const DEFAULT_PREFIX = `\
106
+ Your goal is to structure the user's query to match the request schema provided below.
107
+
108
+ {schema}\
109
+ `;
110
+ export const DEFAULT_SUFFIX = `\
111
+ << Example {i}. >>
112
+ Data Source:
113
+ \`\`\`json
114
+ {{{{
115
+ content: {content},
116
+ attributes: {attributes}
117
+ }}}}
118
+ \`\`\`
119
+
120
+ User Query:
121
+ {{query}}
122
+
123
+ Structured Request:
124
+ `;
@@ -50,6 +50,12 @@ class SqlDatabaseChain extends base_js_1.BaseChain {
50
50
  writable: true,
51
51
  value: "result"
52
52
  });
53
+ Object.defineProperty(this, "sqlOutputKey", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: undefined
58
+ });
53
59
  // Whether to return the result of querying the SQL table directly.
54
60
  Object.defineProperty(this, "returnDirect", {
55
61
  enumerable: true,
@@ -62,6 +68,7 @@ class SqlDatabaseChain extends base_js_1.BaseChain {
62
68
  this.topK = fields.topK ?? this.topK;
63
69
  this.inputKey = fields.inputKey ?? this.inputKey;
64
70
  this.outputKey = fields.outputKey ?? this.outputKey;
71
+ this.sqlOutputKey = fields.sqlOutputKey ?? this.sqlOutputKey;
65
72
  this.prompt =
66
73
  fields.prompt ??
67
74
  (0, sql_utils_js_1.getPromptTemplateFromDataSource)(this.database.appDataSource);
@@ -111,6 +118,9 @@ class SqlDatabaseChain extends base_js_1.BaseChain {
111
118
  [this.outputKey]: await llmChain.predict(llmInputs, runManager?.getChild()),
112
119
  };
113
120
  }
121
+ if (this.sqlOutputKey != null) {
122
+ finalResult[this.sqlOutputKey] = sqlCommand;
123
+ }
114
124
  return finalResult;
115
125
  }
116
126
  _chainType() {
@@ -120,6 +130,9 @@ class SqlDatabaseChain extends base_js_1.BaseChain {
120
130
  return [this.inputKey];
121
131
  }
122
132
  get outputKeys() {
133
+ if (this.sqlOutputKey != null) {
134
+ return [this.outputKey, this.sqlOutputKey];
135
+ }
123
136
  return [this.outputKey];
124
137
  }
125
138
  static async deserialize(data, SqlDatabaseFromOptionsParams) {
@@ -11,6 +11,7 @@ export interface SqlDatabaseChainInput extends ChainInputs {
11
11
  topK?: number;
12
12
  inputKey?: string;
13
13
  outputKey?: string;
14
+ sqlOutputKey?: string;
14
15
  prompt?: PromptTemplate;
15
16
  }
16
17
  export declare class SqlDatabaseChain extends BaseChain {
@@ -20,6 +21,7 @@ export declare class SqlDatabaseChain extends BaseChain {
20
21
  topK: number;
21
22
  inputKey: string;
22
23
  outputKey: string;
24
+ sqlOutputKey: string | undefined;
23
25
  returnDirect: boolean;
24
26
  constructor(fields: SqlDatabaseChainInput);
25
27
  /** @ignore */
@@ -47,6 +47,12 @@ export class SqlDatabaseChain extends BaseChain {
47
47
  writable: true,
48
48
  value: "result"
49
49
  });
50
+ Object.defineProperty(this, "sqlOutputKey", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: undefined
55
+ });
50
56
  // Whether to return the result of querying the SQL table directly.
51
57
  Object.defineProperty(this, "returnDirect", {
52
58
  enumerable: true,
@@ -59,6 +65,7 @@ export class SqlDatabaseChain extends BaseChain {
59
65
  this.topK = fields.topK ?? this.topK;
60
66
  this.inputKey = fields.inputKey ?? this.inputKey;
61
67
  this.outputKey = fields.outputKey ?? this.outputKey;
68
+ this.sqlOutputKey = fields.sqlOutputKey ?? this.sqlOutputKey;
62
69
  this.prompt =
63
70
  fields.prompt ??
64
71
  getPromptTemplateFromDataSource(this.database.appDataSource);
@@ -108,6 +115,9 @@ export class SqlDatabaseChain extends BaseChain {
108
115
  [this.outputKey]: await llmChain.predict(llmInputs, runManager?.getChild()),
109
116
  };
110
117
  }
118
+ if (this.sqlOutputKey != null) {
119
+ finalResult[this.sqlOutputKey] = sqlCommand;
120
+ }
111
121
  return finalResult;
112
122
  }
113
123
  _chainType() {
@@ -117,6 +127,9 @@ export class SqlDatabaseChain extends BaseChain {
117
127
  return [this.inputKey];
118
128
  }
119
129
  get outputKeys() {
130
+ if (this.sqlOutputKey != null) {
131
+ return [this.outputKey, this.sqlOutputKey];
132
+ }
120
133
  return [this.outputKey];
121
134
  }
122
135
  static async deserialize(data, SqlDatabaseFromOptionsParams) {
@@ -3,18 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LangChainPlusClient = exports.isChain = exports.isChatModel = exports.isLLM = void 0;
4
4
  const tracer_langchain_js_1 = require("../callbacks/handlers/tracer_langchain.cjs");
5
5
  const utils_js_1 = require("../stores/message/utils.cjs");
6
+ const async_caller_js_1 = require("../util/async_caller.cjs");
6
7
  // utility functions
7
8
  const isLocalhost = (url) => {
8
9
  const strippedUrl = url.replace("http://", "").replace("https://", "");
9
10
  const hostname = strippedUrl.split("/")[0].split(":")[0];
10
11
  return (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1");
11
12
  };
12
- const getSeededTenantId = async (apiUrl, apiKey) => {
13
+ const getSeededTenantId = async (apiUrl, apiKey, callerOptions = undefined) => {
13
14
  // Get the tenant ID from the seeded tenant
15
+ const caller = new async_caller_js_1.AsyncCaller(callerOptions ?? {});
14
16
  const url = `${apiUrl}/tenants`;
15
17
  let response;
16
18
  try {
17
- response = await fetch(url, {
19
+ response = await caller.call(fetch, url, {
18
20
  method: "GET",
19
21
  headers: apiKey ? { authorization: `Bearer ${apiKey}` } : undefined,
20
22
  });
@@ -80,7 +82,7 @@ async function getModelOrFactoryType(llm) {
80
82
  throw new Error("Unknown model or factory type");
81
83
  }
82
84
  class LangChainPlusClient {
83
- constructor(apiUrl, tenantId, apiKey) {
85
+ constructor(apiUrl, tenantId, apiKey, callerOptions) {
84
86
  Object.defineProperty(this, "apiKey", {
85
87
  enumerable: true,
86
88
  configurable: true,
@@ -99,17 +101,21 @@ class LangChainPlusClient {
99
101
  writable: true,
100
102
  value: void 0
101
103
  });
104
+ Object.defineProperty(this, "caller", {
105
+ enumerable: true,
106
+ configurable: true,
107
+ writable: true,
108
+ value: void 0
109
+ });
102
110
  this.apiUrl = apiUrl;
103
111
  this.apiKey = apiKey;
104
112
  this.tenantId = tenantId;
105
113
  this.validateApiKeyIfHosted();
114
+ this.caller = new async_caller_js_1.AsyncCaller(callerOptions ?? {});
106
115
  }
107
- static async create(apiUrl, apiKey = undefined, tenantId = undefined) {
108
- let tenantId_ = tenantId;
109
- if (!tenantId_) {
110
- tenantId_ = await getSeededTenantId(apiUrl, apiKey);
111
- }
112
- return new LangChainPlusClient(apiUrl, tenantId_, apiKey);
116
+ static async create(apiUrl, apiKey = undefined) {
117
+ const tenantId = await getSeededTenantId(apiUrl, apiKey);
118
+ return new LangChainPlusClient(apiUrl, tenantId, apiKey);
113
119
  }
114
120
  validateApiKeyIfHosted() {
115
121
  const isLocal = isLocalhost(this.apiUrl);
@@ -138,7 +144,7 @@ class LangChainPlusClient {
138
144
  }
139
145
  }
140
146
  const url = `${this.apiUrl}${path}${queryString ? `?${queryString}` : ""}`;
141
- const response = await fetch(url, {
147
+ const response = await this.caller.call(fetch, url, {
142
148
  method: "GET",
143
149
  headers: this.headers,
144
150
  });
@@ -155,7 +161,7 @@ class LangChainPlusClient {
155
161
  formData.append("output_keys", outputKeys.join(","));
156
162
  formData.append("description", description);
157
163
  formData.append("tenant_id", this.tenantId);
158
- const response = await fetch(url, {
164
+ const response = await this.caller.call(fetch, url, {
159
165
  method: "POST",
160
166
  headers: this.headers,
161
167
  body: formData,
@@ -171,7 +177,7 @@ class LangChainPlusClient {
171
177
  return result;
172
178
  }
173
179
  async createDataset(name, description) {
174
- const response = await fetch(`${this.apiUrl}/datasets`, {
180
+ const response = await this.caller.call(fetch, `${this.apiUrl}/datasets`, {
175
181
  method: "POST",
176
182
  headers: { ...this.headers, "Content-Type": "application/json" },
177
183
  body: JSON.stringify({
@@ -245,7 +251,7 @@ class LangChainPlusClient {
245
251
  else {
246
252
  throw new Error("Must provide datasetName or datasetId");
247
253
  }
248
- const response = await fetch(this.apiUrl + path, {
254
+ const response = await this.caller.call(fetch, this.apiUrl + path, {
249
255
  method: "DELETE",
250
256
  headers: this.headers,
251
257
  });
@@ -274,7 +280,7 @@ class LangChainPlusClient {
274
280
  outputs,
275
281
  created_at: createdAt_.toISOString(),
276
282
  };
277
- const response = await fetch(`${this.apiUrl}/examples`, {
283
+ const response = await this.caller.call(fetch, `${this.apiUrl}/examples`, {
278
284
  method: "POST",
279
285
  headers: { ...this.headers, "Content-Type": "application/json" },
280
286
  body: JSON.stringify(data),
@@ -314,7 +320,7 @@ class LangChainPlusClient {
314
320
  }
315
321
  async deleteExample(exampleId) {
316
322
  const path = `/examples/${exampleId}`;
317
- const response = await fetch(this.apiUrl + path, {
323
+ const response = await this.caller.call(fetch, this.apiUrl + path, {
318
324
  method: "DELETE",
319
325
  headers: this.headers,
320
326
  });
@@ -5,6 +5,7 @@ import { BaseLanguageModel } from "../base_language/index.js";
5
5
  import { BaseChain } from "../chains/base.js";
6
6
  import { BaseLLM } from "../llms/base.js";
7
7
  import { BaseChatModel } from "../chat_models/base.js";
8
+ import { AsyncCallerParams } from "../util/async_caller.js";
8
9
  export interface RunResult extends BaseRun {
9
10
  name: string;
10
11
  session_id: string;
@@ -43,8 +44,9 @@ export declare class LangChainPlusClient {
43
44
  private apiKey?;
44
45
  private apiUrl;
45
46
  private tenantId;
46
- constructor(apiUrl: string, tenantId: string, apiKey?: string);
47
- static create(apiUrl: string, apiKey?: string | undefined, tenantId?: string | undefined): Promise<LangChainPlusClient>;
47
+ private caller;
48
+ constructor(apiUrl: string, tenantId: string, apiKey?: string, callerOptions?: AsyncCallerParams);
49
+ static create(apiUrl: string, apiKey?: string | undefined): Promise<LangChainPlusClient>;
48
50
  private validateApiKeyIfHosted;
49
51
  private get headers();
50
52
  private get queryParams();
@@ -1,17 +1,19 @@
1
1
  import { LangChainTracer } from "../callbacks/handlers/tracer_langchain.js";
2
2
  import { mapStoredMessagesToChatMessages } from "../stores/message/utils.js";
3
+ import { AsyncCaller } from "../util/async_caller.js";
3
4
  // utility functions
4
5
  const isLocalhost = (url) => {
5
6
  const strippedUrl = url.replace("http://", "").replace("https://", "");
6
7
  const hostname = strippedUrl.split("/")[0].split(":")[0];
7
8
  return (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1");
8
9
  };
9
- const getSeededTenantId = async (apiUrl, apiKey) => {
10
+ const getSeededTenantId = async (apiUrl, apiKey, callerOptions = undefined) => {
10
11
  // Get the tenant ID from the seeded tenant
12
+ const caller = new AsyncCaller(callerOptions ?? {});
11
13
  const url = `${apiUrl}/tenants`;
12
14
  let response;
13
15
  try {
14
- response = await fetch(url, {
16
+ response = await caller.call(fetch, url, {
15
17
  method: "GET",
16
18
  headers: apiKey ? { authorization: `Bearer ${apiKey}` } : undefined,
17
19
  });
@@ -74,7 +76,7 @@ async function getModelOrFactoryType(llm) {
74
76
  throw new Error("Unknown model or factory type");
75
77
  }
76
78
  export class LangChainPlusClient {
77
- constructor(apiUrl, tenantId, apiKey) {
79
+ constructor(apiUrl, tenantId, apiKey, callerOptions) {
78
80
  Object.defineProperty(this, "apiKey", {
79
81
  enumerable: true,
80
82
  configurable: true,
@@ -93,17 +95,21 @@ export class LangChainPlusClient {
93
95
  writable: true,
94
96
  value: void 0
95
97
  });
98
+ Object.defineProperty(this, "caller", {
99
+ enumerable: true,
100
+ configurable: true,
101
+ writable: true,
102
+ value: void 0
103
+ });
96
104
  this.apiUrl = apiUrl;
97
105
  this.apiKey = apiKey;
98
106
  this.tenantId = tenantId;
99
107
  this.validateApiKeyIfHosted();
108
+ this.caller = new AsyncCaller(callerOptions ?? {});
100
109
  }
101
- static async create(apiUrl, apiKey = undefined, tenantId = undefined) {
102
- let tenantId_ = tenantId;
103
- if (!tenantId_) {
104
- tenantId_ = await getSeededTenantId(apiUrl, apiKey);
105
- }
106
- return new LangChainPlusClient(apiUrl, tenantId_, apiKey);
110
+ static async create(apiUrl, apiKey = undefined) {
111
+ const tenantId = await getSeededTenantId(apiUrl, apiKey);
112
+ return new LangChainPlusClient(apiUrl, tenantId, apiKey);
107
113
  }
108
114
  validateApiKeyIfHosted() {
109
115
  const isLocal = isLocalhost(this.apiUrl);
@@ -132,7 +138,7 @@ export class LangChainPlusClient {
132
138
  }
133
139
  }
134
140
  const url = `${this.apiUrl}${path}${queryString ? `?${queryString}` : ""}`;
135
- const response = await fetch(url, {
141
+ const response = await this.caller.call(fetch, url, {
136
142
  method: "GET",
137
143
  headers: this.headers,
138
144
  });
@@ -149,7 +155,7 @@ export class LangChainPlusClient {
149
155
  formData.append("output_keys", outputKeys.join(","));
150
156
  formData.append("description", description);
151
157
  formData.append("tenant_id", this.tenantId);
152
- const response = await fetch(url, {
158
+ const response = await this.caller.call(fetch, url, {
153
159
  method: "POST",
154
160
  headers: this.headers,
155
161
  body: formData,
@@ -165,7 +171,7 @@ export class LangChainPlusClient {
165
171
  return result;
166
172
  }
167
173
  async createDataset(name, description) {
168
- const response = await fetch(`${this.apiUrl}/datasets`, {
174
+ const response = await this.caller.call(fetch, `${this.apiUrl}/datasets`, {
169
175
  method: "POST",
170
176
  headers: { ...this.headers, "Content-Type": "application/json" },
171
177
  body: JSON.stringify({
@@ -239,7 +245,7 @@ export class LangChainPlusClient {
239
245
  else {
240
246
  throw new Error("Must provide datasetName or datasetId");
241
247
  }
242
- const response = await fetch(this.apiUrl + path, {
248
+ const response = await this.caller.call(fetch, this.apiUrl + path, {
243
249
  method: "DELETE",
244
250
  headers: this.headers,
245
251
  });
@@ -268,7 +274,7 @@ export class LangChainPlusClient {
268
274
  outputs,
269
275
  created_at: createdAt_.toISOString(),
270
276
  };
271
- const response = await fetch(`${this.apiUrl}/examples`, {
277
+ const response = await this.caller.call(fetch, `${this.apiUrl}/examples`, {
272
278
  method: "POST",
273
279
  headers: { ...this.headers, "Content-Type": "application/json" },
274
280
  body: JSON.stringify(data),
@@ -308,7 +314,7 @@ export class LangChainPlusClient {
308
314
  }
309
315
  async deleteExample(exampleId) {
310
316
  const path = `/examples/${exampleId}`;
311
- const response = await fetch(this.apiUrl + path, {
317
+ const response = await this.caller.call(fetch, this.apiUrl + path, {
312
318
  method: "DELETE",
313
319
  headers: this.headers,
314
320
  });