langchain 0.0.195 → 0.0.197-rc.0

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 (236) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agents/openai/index.cjs +6 -2
  3. package/dist/agents/openai/index.js +6 -2
  4. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
  5. package/dist/base_language/count_tokens.cjs +5 -70
  6. package/dist/base_language/count_tokens.d.ts +1 -10
  7. package/dist/base_language/count_tokens.js +1 -65
  8. package/dist/base_language/index.cjs +6 -196
  9. package/dist/base_language/index.d.ts +1 -111
  10. package/dist/base_language/index.js +1 -191
  11. package/dist/cache/base.cjs +15 -37
  12. package/dist/cache/base.d.ts +1 -20
  13. package/dist/cache/base.js +1 -33
  14. package/dist/cache/index.cjs +2 -46
  15. package/dist/cache/index.d.ts +1 -29
  16. package/dist/cache/index.js +1 -45
  17. package/dist/callbacks/base.cjs +3 -139
  18. package/dist/callbacks/base.d.ts +1 -266
  19. package/dist/callbacks/base.js +1 -126
  20. package/dist/callbacks/handlers/console.cjs +14 -221
  21. package/dist/callbacks/handlers/console.d.ts +1 -117
  22. package/dist/callbacks/handlers/console.js +1 -217
  23. package/dist/callbacks/handlers/initialize.cjs +15 -30
  24. package/dist/callbacks/handlers/initialize.d.ts +1 -16
  25. package/dist/callbacks/handlers/initialize.js +1 -27
  26. package/dist/callbacks/handlers/log_stream.cjs +15 -293
  27. package/dist/callbacks/handlers/log_stream.d.ts +1 -100
  28. package/dist/callbacks/handlers/log_stream.js +1 -289
  29. package/dist/callbacks/handlers/run_collector.cjs +15 -48
  30. package/dist/callbacks/handlers/run_collector.d.ts +1 -26
  31. package/dist/callbacks/handlers/run_collector.js +1 -46
  32. package/dist/callbacks/handlers/tracer.cjs +15 -375
  33. package/dist/callbacks/handlers/tracer.d.ts +1 -70
  34. package/dist/callbacks/handlers/tracer.js +1 -373
  35. package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
  36. package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
  37. package/dist/callbacks/handlers/tracer_langchain.js +1 -102
  38. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
  39. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
  40. package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
  41. package/dist/callbacks/manager.cjs +15 -676
  42. package/dist/callbacks/manager.d.ts +1 -180
  43. package/dist/callbacks/manager.js +1 -666
  44. package/dist/callbacks/promises.cjs +14 -42
  45. package/dist/callbacks/promises.d.ts +1 -11
  46. package/dist/callbacks/promises.js +1 -37
  47. package/dist/chains/graph_qa/prompts.d.ts +1 -1
  48. package/dist/chains/openai_functions/structured_output.cjs +2 -2
  49. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  50. package/dist/chains/openai_functions/structured_output.js +1 -1
  51. package/dist/chat_models/anthropic.cjs +15 -348
  52. package/dist/chat_models/anthropic.d.ts +1 -156
  53. package/dist/chat_models/anthropic.js +1 -346
  54. package/dist/chat_models/baiduwenxin.d.ts +1 -1
  55. package/dist/chat_models/base.cjs +15 -296
  56. package/dist/chat_models/base.d.ts +1 -122
  57. package/dist/chat_models/base.js +1 -292
  58. package/dist/chat_models/bedrock/web.cjs +21 -1
  59. package/dist/chat_models/bedrock/web.d.ts +2 -2
  60. package/dist/chat_models/bedrock/web.js +21 -1
  61. package/dist/chat_models/fireworks.d.ts +1 -1
  62. package/dist/document.cjs +2 -24
  63. package/dist/document.d.ts +1 -12
  64. package/dist/document.js +1 -23
  65. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
  66. package/dist/document_loaders/web/github.cjs +105 -0
  67. package/dist/document_loaders/web/github.d.ts +26 -0
  68. package/dist/document_loaders/web/github.js +105 -0
  69. package/dist/document_loaders/web/s3.d.ts +1 -1
  70. package/dist/embeddings/base.cjs +15 -22
  71. package/dist/embeddings/base.d.ts +1 -33
  72. package/dist/embeddings/base.js +1 -20
  73. package/dist/embeddings/cache_backed.cjs +2 -2
  74. package/dist/embeddings/cache_backed.js +1 -1
  75. package/dist/evaluation/agents/trajectory.d.ts +1 -1
  76. package/dist/evaluation/criteria/prompt.d.ts +2 -2
  77. package/dist/evaluation/qa/prompt.d.ts +2 -2
  78. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
  79. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  80. package/dist/llms/base.cjs +15 -278
  81. package/dist/llms/base.d.ts +1 -115
  82. package/dist/llms/base.js +1 -275
  83. package/dist/llms/bedrock/web.cjs +21 -1
  84. package/dist/llms/bedrock/web.d.ts +2 -2
  85. package/dist/llms/bedrock/web.js +21 -1
  86. package/dist/llms/fireworks.d.ts +1 -1
  87. package/dist/load/import_map.cjs +2 -1
  88. package/dist/load/import_map.d.ts +1 -0
  89. package/dist/load/import_map.js +1 -0
  90. package/dist/load/index.cjs +7 -148
  91. package/dist/load/index.js +7 -148
  92. package/dist/load/map_keys.cjs +0 -24
  93. package/dist/load/map_keys.d.ts +0 -6
  94. package/dist/load/map_keys.js +1 -17
  95. package/dist/load/serializable.cjs +15 -178
  96. package/dist/load/serializable.d.ts +1 -66
  97. package/dist/load/serializable.js +1 -175
  98. package/dist/memory/base.cjs +17 -92
  99. package/dist/memory/base.d.ts +2 -68
  100. package/dist/memory/base.js +2 -87
  101. package/dist/output_parsers/list.cjs +4 -122
  102. package/dist/output_parsers/list.d.ts +1 -57
  103. package/dist/output_parsers/list.js +1 -119
  104. package/dist/output_parsers/openai_functions.cjs +2 -2
  105. package/dist/output_parsers/openai_functions.d.ts +1 -1
  106. package/dist/output_parsers/openai_functions.js +1 -1
  107. package/dist/output_parsers/regex.d.ts +1 -1
  108. package/dist/output_parsers/structured.d.ts +1 -1
  109. package/dist/prompts/base.cjs +8 -183
  110. package/dist/prompts/base.d.ts +3 -132
  111. package/dist/prompts/base.js +3 -178
  112. package/dist/prompts/chat.cjs +13 -477
  113. package/dist/prompts/chat.d.ts +2 -219
  114. package/dist/prompts/chat.js +2 -466
  115. package/dist/prompts/few_shot.cjs +3 -352
  116. package/dist/prompts/few_shot.d.ts +1 -192
  117. package/dist/prompts/few_shot.js +1 -350
  118. package/dist/prompts/index.cjs +3 -2
  119. package/dist/prompts/index.d.ts +2 -1
  120. package/dist/prompts/index.js +2 -1
  121. package/dist/prompts/pipeline.cjs +2 -141
  122. package/dist/prompts/pipeline.d.ts +1 -98
  123. package/dist/prompts/pipeline.js +1 -140
  124. package/dist/prompts/prompt.cjs +2 -145
  125. package/dist/prompts/prompt.d.ts +1 -92
  126. package/dist/prompts/prompt.js +1 -144
  127. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +2 -147
  128. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
  129. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
  130. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
  131. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
  132. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
  133. package/dist/prompts/selectors/conditional.cjs +5 -73
  134. package/dist/prompts/selectors/conditional.d.ts +1 -63
  135. package/dist/prompts/selectors/conditional.js +1 -69
  136. package/dist/prompts/serde.d.ts +1 -43
  137. package/dist/prompts/template.cjs +8 -88
  138. package/dist/prompts/template.d.ts +1 -36
  139. package/dist/prompts/template.js +1 -83
  140. package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
  141. package/dist/runnables/index.d.ts +1 -0
  142. package/dist/runnables/index.js +1 -0
  143. package/dist/schema/document.cjs +3 -34
  144. package/dist/schema/document.d.ts +2 -29
  145. package/dist/schema/document.js +2 -32
  146. package/dist/schema/index.cjs +37 -612
  147. package/dist/schema/index.d.ts +11 -311
  148. package/dist/schema/index.js +8 -583
  149. package/dist/schema/output_parser.cjs +15 -309
  150. package/dist/schema/output_parser.d.ts +1 -173
  151. package/dist/schema/output_parser.js +1 -301
  152. package/dist/schema/retriever.cjs +15 -77
  153. package/dist/schema/retriever.d.ts +1 -43
  154. package/dist/schema/retriever.js +1 -75
  155. package/dist/schema/runnable/base.cjs +10 -1072
  156. package/dist/schema/runnable/base.d.ts +1 -356
  157. package/dist/schema/runnable/base.js +1 -1060
  158. package/dist/schema/runnable/branch.cjs +2 -131
  159. package/dist/schema/runnable/branch.d.ts +1 -94
  160. package/dist/schema/runnable/branch.js +1 -130
  161. package/dist/schema/runnable/config.cjs +0 -6
  162. package/dist/schema/runnable/config.d.ts +1 -3
  163. package/dist/schema/runnable/config.js +1 -4
  164. package/dist/schema/runnable/index.cjs +15 -16
  165. package/dist/schema/runnable/index.d.ts +1 -5
  166. package/dist/schema/runnable/index.js +1 -4
  167. package/dist/schema/runnable/passthrough.cjs +3 -113
  168. package/dist/schema/runnable/passthrough.d.ts +1 -72
  169. package/dist/schema/runnable/passthrough.js +1 -111
  170. package/dist/schema/runnable/router.cjs +2 -71
  171. package/dist/schema/runnable/router.d.ts +1 -29
  172. package/dist/schema/runnable/router.js +1 -70
  173. package/dist/schema/storage.cjs +15 -8
  174. package/dist/schema/storage.d.ts +1 -57
  175. package/dist/schema/storage.js +1 -6
  176. package/dist/tools/bingserpapi.d.ts +1 -1
  177. package/dist/tools/searchapi.d.ts +1 -1
  178. package/dist/tools/serpapi.d.ts +1 -1
  179. package/dist/tools/serper.d.ts +1 -1
  180. package/dist/util/async_caller.cjs +14 -128
  181. package/dist/util/async_caller.d.ts +1 -45
  182. package/dist/util/async_caller.js +1 -124
  183. package/dist/vectorstores/momento_vector_index.cjs +39 -0
  184. package/dist/vectorstores/momento_vector_index.d.ts +17 -1
  185. package/dist/vectorstores/momento_vector_index.js +40 -1
  186. package/dist/vectorstores/mongodb_atlas.cjs +22 -2
  187. package/dist/vectorstores/mongodb_atlas.d.ts +13 -0
  188. package/dist/vectorstores/mongodb_atlas.js +22 -2
  189. package/package.json +18 -11
  190. package/runnables.cjs +1 -0
  191. package/runnables.d.ts +1 -0
  192. package/runnables.js +1 -0
  193. package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
  194. package/dist/util/@cfworker/json-schema/index.js +0 -1
  195. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
  196. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
  197. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
  198. package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
  199. package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
  200. package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
  201. package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
  202. package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
  203. package/dist/util/@cfworker/json-schema/src/format.js +0 -136
  204. package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
  205. package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
  206. package/dist/util/@cfworker/json-schema/src/index.js +0 -8
  207. package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
  208. package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
  209. package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
  210. package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
  211. package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
  212. package/dist/util/@cfworker/json-schema/src/types.js +0 -1
  213. package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
  214. package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
  215. package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
  216. package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
  217. package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
  218. package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
  219. package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
  220. package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
  221. package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
  222. package/dist/util/fast-json-patch/index.cjs +0 -49
  223. package/dist/util/fast-json-patch/index.d.ts +0 -22
  224. package/dist/util/fast-json-patch/index.js +0 -16
  225. package/dist/util/fast-json-patch/src/core.cjs +0 -469
  226. package/dist/util/fast-json-patch/src/core.d.ts +0 -111
  227. package/dist/util/fast-json-patch/src/core.js +0 -459
  228. package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
  229. package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
  230. package/dist/util/fast-json-patch/src/duplex.js +0 -230
  231. package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
  232. package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
  233. package/dist/util/fast-json-patch/src/helpers.js +0 -181
  234. package/dist/util/js-sha1/hash.cjs +0 -358
  235. package/dist/util/js-sha1/hash.d.ts +0 -1
  236. package/dist/util/js-sha1/hash.js +0 -355
@@ -1,87 +1,2 @@
1
- /**
2
- * Abstract base class for memory in LangChain's Chains. Memory refers to
3
- * the state in Chains. It can be used to store information about past
4
- * executions of a Chain and inject that information into the inputs of
5
- * future executions of the Chain.
6
- */
7
- export class BaseMemory {
8
- }
9
- const getValue = (values, key) => {
10
- if (key !== undefined) {
11
- return values[key];
12
- }
13
- const keys = Object.keys(values);
14
- if (keys.length === 1) {
15
- return values[keys[0]];
16
- }
17
- };
18
- /**
19
- * This function is used by memory classes to select the input value
20
- * to use for the memory. If there is only one input value, it is used.
21
- * If there are multiple input values, the inputKey must be specified.
22
- */
23
- export const getInputValue = (inputValues, inputKey) => {
24
- const value = getValue(inputValues, inputKey);
25
- if (!value) {
26
- const keys = Object.keys(inputValues);
27
- throw new Error(`input values have ${keys.length} keys, you must specify an input key or pass only 1 key as input`);
28
- }
29
- return value;
30
- };
31
- /**
32
- * This function is used by memory classes to select the output value
33
- * to use for the memory. If there is only one output value, it is used.
34
- * If there are multiple output values, the outputKey must be specified.
35
- * If no outputKey is specified, an error is thrown.
36
- */
37
- export const getOutputValue = (outputValues, outputKey) => {
38
- const value = getValue(outputValues, outputKey);
39
- if (!value) {
40
- const keys = Object.keys(outputValues);
41
- throw new Error(`output values have ${keys.length} keys, you must specify an output key or pass only 1 key as output`);
42
- }
43
- return value;
44
- };
45
- /**
46
- * This function is used by memory classes to get a string representation
47
- * of the chat message history, based on the message content and role.
48
- */
49
- export function getBufferString(messages, humanPrefix = "Human", aiPrefix = "AI") {
50
- const string_messages = [];
51
- for (const m of messages) {
52
- let role;
53
- if (m._getType() === "human") {
54
- role = humanPrefix;
55
- }
56
- else if (m._getType() === "ai") {
57
- role = aiPrefix;
58
- }
59
- else if (m._getType() === "system") {
60
- role = "System";
61
- }
62
- else if (m._getType() === "function") {
63
- role = "Function";
64
- }
65
- else if (m._getType() === "generic") {
66
- role = m.role;
67
- }
68
- else {
69
- throw new Error(`Got unsupported message type: ${m}`);
70
- }
71
- const nameStr = m.name ? `${m.name}, ` : "";
72
- string_messages.push(`${role}: ${nameStr}${m.content}`);
73
- }
74
- return string_messages.join("\n");
75
- }
76
- /**
77
- * Function used by memory classes to get the key of the prompt input,
78
- * excluding any keys that are memory variables or the "stop" key. If
79
- * there is not exactly one prompt input key, an error is thrown.
80
- */
81
- export function getPromptInputKey(inputs, memoryVariables) {
82
- const promptInputKeys = Object.keys(inputs).filter((key) => !memoryVariables.includes(key) && key !== "stop");
83
- if (promptInputKeys.length !== 1) {
84
- throw new Error(`One input key expected, but got ${promptInputKeys.length}`);
85
- }
86
- return promptInputKeys[0];
87
- }
1
+ export * from "langchain-core/memory";
2
+ export { getBufferString } from "langchain-core/messages";
@@ -1,125 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CustomListOutputParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
4
- const output_parser_js_1 = require("../schema/output_parser.cjs");
5
- /**
6
- * Class to parse the output of an LLM call to a list.
7
- * @augments BaseOutputParser
8
- */
9
- class ListOutputParser extends output_parser_js_1.BaseOutputParser {
10
- }
11
- exports.ListOutputParser = ListOutputParser;
12
- /**
13
- * Class to parse the output of an LLM call as a comma-separated list.
14
- * @augments ListOutputParser
15
- */
16
- class CommaSeparatedListOutputParser extends ListOutputParser {
17
- constructor() {
18
- super(...arguments);
19
- Object.defineProperty(this, "lc_namespace", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: ["langchain", "output_parsers", "list"]
24
- });
25
- Object.defineProperty(this, "lc_serializable", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: true
30
- });
31
- }
32
- static lc_name() {
33
- return "CommaSeparatedListOutputParser";
34
- }
35
- /**
36
- * Parses the given text into an array of strings, using a comma as the
37
- * separator. If the parsing fails, throws an OutputParserException.
38
- * @param text The text to parse.
39
- * @returns An array of strings obtained by splitting the input text at each comma.
40
- */
41
- async parse(text) {
42
- try {
43
- return text
44
- .trim()
45
- .split(",")
46
- .map((s) => s.trim());
47
- }
48
- catch (e) {
49
- throw new output_parser_js_1.OutputParserException(`Could not parse output: ${text}`, text);
50
- }
51
- }
52
- /**
53
- * Provides instructions on the expected format of the response for the
54
- * CommaSeparatedListOutputParser.
55
- * @returns A string containing instructions on the expected format of the response.
56
- */
57
- getFormatInstructions() {
58
- return `Your response should be a list of comma separated values, eg: \`foo, bar, baz\``;
59
- }
60
- }
61
- exports.CommaSeparatedListOutputParser = CommaSeparatedListOutputParser;
62
- /**
63
- * Class to parse the output of an LLM call to a list with a specific length and separator.
64
- * @augments ListOutputParser
65
- */
66
- class CustomListOutputParser extends ListOutputParser {
67
- constructor({ length, separator }) {
68
- super(...arguments);
69
- Object.defineProperty(this, "lc_namespace", {
70
- enumerable: true,
71
- configurable: true,
72
- writable: true,
73
- value: ["langchain", "output_parsers", "list"]
74
- });
75
- Object.defineProperty(this, "length", {
76
- enumerable: true,
77
- configurable: true,
78
- writable: true,
79
- value: void 0
80
- });
81
- Object.defineProperty(this, "separator", {
82
- enumerable: true,
83
- configurable: true,
84
- writable: true,
85
- value: void 0
86
- });
87
- this.length = length;
88
- this.separator = separator || ",";
89
- }
90
- /**
91
- * Parses the given text into an array of strings, using the specified
92
- * separator. If the parsing fails or the number of items in the list
93
- * doesn't match the expected length, throws an OutputParserException.
94
- * @param text The text to parse.
95
- * @returns An array of strings obtained by splitting the input text at each occurrence of the specified separator.
96
- */
97
- async parse(text) {
98
- try {
99
- const items = text
100
- .trim()
101
- .split(this.separator)
102
- .map((s) => s.trim());
103
- if (this.length !== undefined && items.length !== this.length) {
104
- throw new output_parser_js_1.OutputParserException(`Incorrect number of items. Expected ${this.length}, got ${items.length}.`);
105
- }
106
- return items;
107
- }
108
- catch (e) {
109
- if (Object.getPrototypeOf(e) === output_parser_js_1.OutputParserException.prototype) {
110
- throw e;
111
- }
112
- throw new output_parser_js_1.OutputParserException(`Could not parse output: ${text}`);
113
- }
114
- }
115
- /**
116
- * Provides instructions on the expected format of the response for the
117
- * CustomListOutputParser, including the number of items and the
118
- * separator.
119
- * @returns A string containing instructions on the expected format of the response.
120
- */
121
- getFormatInstructions() {
122
- return `Your response should be a list of ${this.length === undefined ? "" : `${this.length} `}items separated by "${this.separator}" (eg: \`foo${this.separator} bar${this.separator} baz\`)`;
123
- }
124
- }
125
- exports.CustomListOutputParser = CustomListOutputParser;
4
+ var output_parsers_1 = require("langchain-core/output_parsers");
5
+ Object.defineProperty(exports, "ListOutputParser", { enumerable: true, get: function () { return output_parsers_1.ListOutputParser; } });
6
+ Object.defineProperty(exports, "CommaSeparatedListOutputParser", { enumerable: true, get: function () { return output_parsers_1.CommaSeparatedListOutputParser; } });
7
+ Object.defineProperty(exports, "CustomListOutputParser", { enumerable: true, get: function () { return output_parsers_1.CustomListOutputParser; } });
@@ -1,57 +1 @@
1
- import { BaseOutputParser } from "../schema/output_parser.js";
2
- /**
3
- * Class to parse the output of an LLM call to a list.
4
- * @augments BaseOutputParser
5
- */
6
- export declare abstract class ListOutputParser extends BaseOutputParser<string[]> {
7
- }
8
- /**
9
- * Class to parse the output of an LLM call as a comma-separated list.
10
- * @augments ListOutputParser
11
- */
12
- export declare class CommaSeparatedListOutputParser extends ListOutputParser {
13
- static lc_name(): string;
14
- lc_namespace: string[];
15
- lc_serializable: boolean;
16
- /**
17
- * Parses the given text into an array of strings, using a comma as the
18
- * separator. If the parsing fails, throws an OutputParserException.
19
- * @param text The text to parse.
20
- * @returns An array of strings obtained by splitting the input text at each comma.
21
- */
22
- parse(text: string): Promise<string[]>;
23
- /**
24
- * Provides instructions on the expected format of the response for the
25
- * CommaSeparatedListOutputParser.
26
- * @returns A string containing instructions on the expected format of the response.
27
- */
28
- getFormatInstructions(): string;
29
- }
30
- /**
31
- * Class to parse the output of an LLM call to a list with a specific length and separator.
32
- * @augments ListOutputParser
33
- */
34
- export declare class CustomListOutputParser extends ListOutputParser {
35
- lc_namespace: string[];
36
- private length;
37
- private separator;
38
- constructor({ length, separator }: {
39
- length?: number;
40
- separator?: string;
41
- });
42
- /**
43
- * Parses the given text into an array of strings, using the specified
44
- * separator. If the parsing fails or the number of items in the list
45
- * doesn't match the expected length, throws an OutputParserException.
46
- * @param text The text to parse.
47
- * @returns An array of strings obtained by splitting the input text at each occurrence of the specified separator.
48
- */
49
- parse(text: string): Promise<string[]>;
50
- /**
51
- * Provides instructions on the expected format of the response for the
52
- * CustomListOutputParser, including the number of items and the
53
- * separator.
54
- * @returns A string containing instructions on the expected format of the response.
55
- */
56
- getFormatInstructions(): string;
57
- }
1
+ export { ListOutputParser, CommaSeparatedListOutputParser, CustomListOutputParser, } from "langchain-core/output_parsers";
@@ -1,119 +1 @@
1
- import { BaseOutputParser, OutputParserException, } from "../schema/output_parser.js";
2
- /**
3
- * Class to parse the output of an LLM call to a list.
4
- * @augments BaseOutputParser
5
- */
6
- export class ListOutputParser extends BaseOutputParser {
7
- }
8
- /**
9
- * Class to parse the output of an LLM call as a comma-separated list.
10
- * @augments ListOutputParser
11
- */
12
- export class CommaSeparatedListOutputParser extends ListOutputParser {
13
- constructor() {
14
- super(...arguments);
15
- Object.defineProperty(this, "lc_namespace", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: ["langchain", "output_parsers", "list"]
20
- });
21
- Object.defineProperty(this, "lc_serializable", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: true
26
- });
27
- }
28
- static lc_name() {
29
- return "CommaSeparatedListOutputParser";
30
- }
31
- /**
32
- * Parses the given text into an array of strings, using a comma as the
33
- * separator. If the parsing fails, throws an OutputParserException.
34
- * @param text The text to parse.
35
- * @returns An array of strings obtained by splitting the input text at each comma.
36
- */
37
- async parse(text) {
38
- try {
39
- return text
40
- .trim()
41
- .split(",")
42
- .map((s) => s.trim());
43
- }
44
- catch (e) {
45
- throw new OutputParserException(`Could not parse output: ${text}`, text);
46
- }
47
- }
48
- /**
49
- * Provides instructions on the expected format of the response for the
50
- * CommaSeparatedListOutputParser.
51
- * @returns A string containing instructions on the expected format of the response.
52
- */
53
- getFormatInstructions() {
54
- return `Your response should be a list of comma separated values, eg: \`foo, bar, baz\``;
55
- }
56
- }
57
- /**
58
- * Class to parse the output of an LLM call to a list with a specific length and separator.
59
- * @augments ListOutputParser
60
- */
61
- export class CustomListOutputParser extends ListOutputParser {
62
- constructor({ length, separator }) {
63
- super(...arguments);
64
- Object.defineProperty(this, "lc_namespace", {
65
- enumerable: true,
66
- configurable: true,
67
- writable: true,
68
- value: ["langchain", "output_parsers", "list"]
69
- });
70
- Object.defineProperty(this, "length", {
71
- enumerable: true,
72
- configurable: true,
73
- writable: true,
74
- value: void 0
75
- });
76
- Object.defineProperty(this, "separator", {
77
- enumerable: true,
78
- configurable: true,
79
- writable: true,
80
- value: void 0
81
- });
82
- this.length = length;
83
- this.separator = separator || ",";
84
- }
85
- /**
86
- * Parses the given text into an array of strings, using the specified
87
- * separator. If the parsing fails or the number of items in the list
88
- * doesn't match the expected length, throws an OutputParserException.
89
- * @param text The text to parse.
90
- * @returns An array of strings obtained by splitting the input text at each occurrence of the specified separator.
91
- */
92
- async parse(text) {
93
- try {
94
- const items = text
95
- .trim()
96
- .split(this.separator)
97
- .map((s) => s.trim());
98
- if (this.length !== undefined && items.length !== this.length) {
99
- throw new OutputParserException(`Incorrect number of items. Expected ${this.length}, got ${items.length}.`);
100
- }
101
- return items;
102
- }
103
- catch (e) {
104
- if (Object.getPrototypeOf(e) === OutputParserException.prototype) {
105
- throw e;
106
- }
107
- throw new OutputParserException(`Could not parse output: ${text}`);
108
- }
109
- }
110
- /**
111
- * Provides instructions on the expected format of the response for the
112
- * CustomListOutputParser, including the number of items and the
113
- * separator.
114
- * @returns A string containing instructions on the expected format of the response.
115
- */
116
- getFormatInstructions() {
117
- return `Your response should be a list of ${this.length === undefined ? "" : `${this.length} `}items separated by "${this.separator}" (eg: \`foo${this.separator} bar${this.separator} baz\`)`;
118
- }
119
- }
1
+ export { ListOutputParser, CommaSeparatedListOutputParser, CustomListOutputParser, } from "langchain-core/output_parsers";
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = void 0;
4
+ const json_patch_1 = require("langchain-core/utils/json_patch");
4
5
  const output_parser_js_1 = require("../schema/output_parser.cjs");
5
- const index_js_1 = require("../util/fast-json-patch/index.cjs");
6
6
  const json_js_1 = require("./json.cjs");
7
7
  /**
8
8
  * Class for parsing the output of an LLM. Can be configured to return
@@ -102,7 +102,7 @@ class JsonOutputFunctionsParser extends output_parser_js_1.BaseCumulativeTransfo
102
102
  if (!next) {
103
103
  return undefined;
104
104
  }
105
- const ops = (0, index_js_1.compare)(prev ?? {}, next);
105
+ const ops = (0, json_patch_1.compare)(prev ?? {}, next);
106
106
  return ops;
107
107
  }
108
108
  async parsePartialResult(generations) {
@@ -1,8 +1,8 @@
1
1
  import { JsonSchema7ObjectType } from "zod-to-json-schema/src/parsers/object.js";
2
+ import { type Operation as JSONPatchOperation } from "langchain-core/utils/json_patch";
2
3
  import { ChatGeneration, Generation } from "../schema/index.js";
3
4
  import { Optional } from "../types/type-utils.js";
4
5
  import { BaseCumulativeTransformOutputParser, type BaseCumulativeTransformOutputParserInput, BaseLLMOutputParser } from "../schema/output_parser.js";
5
- import { type Operation as JSONPatchOperation } from "../util/fast-json-patch/index.js";
6
6
  /**
7
7
  * Represents optional parameters for a function in a JSON Schema.
8
8
  */
@@ -1,5 +1,5 @@
1
+ import { compare, } from "langchain-core/utils/json_patch";
1
2
  import { BaseCumulativeTransformOutputParser, BaseLLMOutputParser, } from "../schema/output_parser.js";
2
- import { compare, } from "../util/fast-json-patch/index.js";
3
3
  import { parsePartialJson } from "./json.js";
4
4
  /**
5
5
  * Class for parsing the output of an LLM. Can be configured to return
@@ -1,4 +1,4 @@
1
- import { SerializedFields } from "../load/map_keys.js";
1
+ import type { SerializedFields } from "../load/map_keys.js";
2
2
  import { BaseOutputParser } from "../schema/output_parser.js";
3
3
  export interface RegExpFields {
4
4
  pattern: string;
@@ -10,7 +10,7 @@ export declare class StructuredOutputParser<T extends z.ZodTypeAny> extends Base
10
10
  schema: T;
11
11
  static lc_name(): string;
12
12
  lc_namespace: string[];
13
- toJSON(): import("../load/serializable.js").SerializedNotImplemented;
13
+ toJSON(): import("langchain-core/load/serializable").SerializedNotImplemented;
14
14
  constructor(schema: T);
15
15
  /**
16
16
  * Creates a new StructuredOutputParser from a Zod schema.
@@ -1,185 +1,10 @@
1
1
  "use strict";
2
- // Default generic "any" values are for backwards compatibility.
3
- // Replace with "string" when we are comfortable with a breaking change.
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.BaseExampleSelector = exports.BaseStringPromptTemplate = exports.BasePromptTemplate = exports.StringPromptValue = void 0;
6
- const index_js_1 = require("../schema/index.cjs");
7
- const serializable_js_1 = require("../load/serializable.cjs");
8
- const index_js_2 = require("../schema/runnable/index.cjs");
9
- /**
10
- * Represents a prompt value as a string. It extends the BasePromptValue
11
- * class and overrides the toString and toChatMessages methods.
12
- */
13
- class StringPromptValue extends index_js_1.BasePromptValue {
14
- constructor(value) {
15
- super({ value });
16
- Object.defineProperty(this, "lc_namespace", {
17
- enumerable: true,
18
- configurable: true,
19
- writable: true,
20
- value: ["langchain", "prompts", "base"]
21
- });
22
- Object.defineProperty(this, "value", {
23
- enumerable: true,
24
- configurable: true,
25
- writable: true,
26
- value: void 0
27
- });
28
- this.value = value;
29
- }
30
- toString() {
31
- return this.value;
32
- }
33
- toChatMessages() {
34
- return [new index_js_1.HumanMessage(this.value)];
35
- }
36
- }
37
- exports.StringPromptValue = StringPromptValue;
38
- /**
39
- * Base class for prompt templates. Exposes a format method that returns a
40
- * string prompt given a set of input values.
41
- */
42
- class BasePromptTemplate extends index_js_2.Runnable {
43
- get lc_attributes() {
44
- return {
45
- partialVariables: undefined, // python doesn't support this yet
46
- };
47
- }
48
- constructor(input) {
49
- super(input);
50
- Object.defineProperty(this, "lc_serializable", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: true
55
- });
56
- Object.defineProperty(this, "lc_namespace", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: ["langchain", "prompts", this._getPromptType()]
61
- });
62
- Object.defineProperty(this, "inputVariables", {
63
- enumerable: true,
64
- configurable: true,
65
- writable: true,
66
- value: void 0
67
- });
68
- Object.defineProperty(this, "outputParser", {
69
- enumerable: true,
70
- configurable: true,
71
- writable: true,
72
- value: void 0
73
- });
74
- Object.defineProperty(this, "partialVariables", {
75
- enumerable: true,
76
- configurable: true,
77
- writable: true,
78
- value: void 0
79
- });
80
- const { inputVariables } = input;
81
- if (inputVariables.includes("stop")) {
82
- throw new Error("Cannot have an input variable named 'stop', as it is used internally, please rename.");
83
- }
84
- Object.assign(this, input);
85
- }
86
- /**
87
- * Merges partial variables and user variables.
88
- * @param userVariables The user variables to merge with the partial variables.
89
- * @returns A Promise that resolves to an object containing the merged variables.
90
- */
91
- async mergePartialAndUserVariables(userVariables) {
92
- const partialVariables = this.partialVariables ?? {};
93
- const partialValues = {};
94
- for (const [key, value] of Object.entries(partialVariables)) {
95
- if (typeof value === "string") {
96
- partialValues[key] = value;
97
- }
98
- else {
99
- partialValues[key] = await value();
100
- }
101
- }
102
- const allKwargs = {
103
- ...partialValues,
104
- ...userVariables,
105
- };
106
- return allKwargs;
107
- }
108
- /**
109
- * Invokes the prompt template with the given input and options.
110
- * @param input The input to invoke the prompt template with.
111
- * @param options Optional configuration for the callback.
112
- * @returns A Promise that resolves to the output of the prompt template.
113
- */
114
- async invoke(input, options) {
115
- return this._callWithConfig((input) => this.formatPromptValue(input), input, { ...options, runType: "prompt" });
116
- }
117
- /**
118
- * Return a json-like object representing this prompt template.
119
- * @deprecated
120
- */
121
- serialize() {
122
- throw new Error("Use .toJSON() instead");
123
- }
124
- /**
125
- * @deprecated
126
- * Load a prompt template from a json-like object describing it.
127
- *
128
- * @remarks
129
- * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can
130
- * reference remote resources that we read asynchronously with a web
131
- * request.
132
- */
133
- static async deserialize(data) {
134
- switch (data._type) {
135
- case "prompt": {
136
- const { PromptTemplate } = await import("./prompt.js");
137
- return PromptTemplate.deserialize(data);
138
- }
139
- case undefined: {
140
- const { PromptTemplate } = await import("./prompt.js");
141
- return PromptTemplate.deserialize({ ...data, _type: "prompt" });
142
- }
143
- case "few_shot": {
144
- const { FewShotPromptTemplate } = await import("./few_shot.js");
145
- return FewShotPromptTemplate.deserialize(data);
146
- }
147
- default:
148
- throw new Error(`Invalid prompt type in config: ${data._type}`);
149
- }
150
- }
151
- }
152
- exports.BasePromptTemplate = BasePromptTemplate;
153
- /**
154
- * Base class for string prompt templates. It extends the
155
- * BasePromptTemplate class and overrides the formatPromptValue method to
156
- * return a StringPromptValue.
157
- */
158
- class BaseStringPromptTemplate extends BasePromptTemplate {
159
- /**
160
- * Formats the prompt given the input values and returns a formatted
161
- * prompt value.
162
- * @param values The input values to format the prompt.
163
- * @returns A Promise that resolves to a formatted prompt value.
164
- */
165
- async formatPromptValue(values) {
166
- const formattedPrompt = await this.format(values);
167
- return new StringPromptValue(formattedPrompt);
168
- }
169
- }
170
- exports.BaseStringPromptTemplate = BaseStringPromptTemplate;
171
- /**
172
- * Base class for example selectors.
173
- */
174
- class BaseExampleSelector extends serializable_js_1.Serializable {
175
- constructor() {
176
- super(...arguments);
177
- Object.defineProperty(this, "lc_namespace", {
178
- enumerable: true,
179
- configurable: true,
180
- writable: true,
181
- value: ["langchain", "prompts", "selectors"]
182
- });
183
- }
184
- }
185
- exports.BaseExampleSelector = BaseExampleSelector;
3
+ exports.BaseExampleSelector = exports.StringPromptValue = exports.BasePromptTemplate = exports.BaseStringPromptTemplate = void 0;
4
+ var prompts_1 = require("langchain-core/prompts");
5
+ Object.defineProperty(exports, "BaseStringPromptTemplate", { enumerable: true, get: function () { return prompts_1.BaseStringPromptTemplate; } });
6
+ Object.defineProperty(exports, "BasePromptTemplate", { enumerable: true, get: function () { return prompts_1.BasePromptTemplate; } });
7
+ var prompt_values_1 = require("langchain-core/prompt_values");
8
+ Object.defineProperty(exports, "StringPromptValue", { enumerable: true, get: function () { return prompt_values_1.StringPromptValue; } });
9
+ var example_selectors_1 = require("langchain-core/example_selectors");
10
+ Object.defineProperty(exports, "BaseExampleSelector", { enumerable: true, get: function () { return example_selectors_1.BaseExampleSelector; } });