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,134 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RunnableBranch = void 0;
4
- const base_js_1 = require("./base.cjs");
5
- /**
6
- * Class that represents a runnable branch. The RunnableBranch is
7
- * initialized with an array of branches and a default branch. When invoked,
8
- * it evaluates the condition of each branch in order and executes the
9
- * corresponding branch if the condition is true. If none of the conditions
10
- * are true, it executes the default branch.
11
- * @example
12
- * ```typescript
13
- * const branch = RunnableBranch.from([
14
- * [
15
- * (x: { topic: string; question: string }) =>
16
- * x.topic.toLowerCase().includes("anthropic"),
17
- * anthropicChain,
18
- * ],
19
- * [
20
- * (x: { topic: string; question: string }) =>
21
- * x.topic.toLowerCase().includes("langchain"),
22
- * langChainChain,
23
- * ],
24
- * generalChain,
25
- * ]);
26
- *
27
- * const fullChain = RunnableSequence.from([
28
- * {
29
- * topic: classificationChain,
30
- * question: (input: { question: string }) => input.question,
31
- * },
32
- * branch,
33
- * ]);
34
- *
35
- * const result = await fullChain.invoke({
36
- * question: "how do I use LangChain?",
37
- * });
38
- * ```
39
- */
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- class RunnableBranch extends base_js_1.Runnable {
42
- static lc_name() {
43
- return "RunnableBranch";
44
- }
45
- constructor(fields) {
46
- super(fields);
47
- Object.defineProperty(this, "lc_namespace", {
48
- enumerable: true,
49
- configurable: true,
50
- writable: true,
51
- value: ["langchain", "runnable", "branch"]
52
- });
53
- Object.defineProperty(this, "lc_serializable", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: true
58
- });
59
- Object.defineProperty(this, "default", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: void 0
64
- });
65
- Object.defineProperty(this, "branches", {
66
- enumerable: true,
67
- configurable: true,
68
- writable: true,
69
- value: void 0
70
- });
71
- this.branches = fields.branches;
72
- this.default = fields.default;
73
- }
74
- /**
75
- * Convenience method for instantiating a RunnableBranch from
76
- * RunnableLikes (objects, functions, or Runnables).
77
- *
78
- * Each item in the input except for the last one should be a
79
- * tuple with two items. The first is a "condition" RunnableLike that
80
- * returns "true" if the second RunnableLike in the tuple should run.
81
- *
82
- * The final item in the input should be a RunnableLike that acts as a
83
- * default branch if no other branches match.
84
- *
85
- * @example
86
- * ```ts
87
- * import { RunnableBranch } from "langchain/schema/runnable";
88
- *
89
- * const branch = RunnableBranch.from([
90
- * [(x: number) => x > 0, (x: number) => x + 1],
91
- * [(x: number) => x < 0, (x: number) => x - 1],
92
- * (x: number) => x
93
- * ]);
94
- * ```
95
- * @param branches An array where the every item except the last is a tuple of [condition, runnable]
96
- * pairs. The last item is a default runnable which is invoked if no other condition matches.
97
- * @returns A new RunnableBranch.
98
- */
99
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
- static from(branches) {
101
- if (branches.length < 1) {
102
- throw new Error("RunnableBranch requires at least one branch");
103
- }
104
- const branchLikes = branches.slice(0, -1);
105
- const coercedBranches = branchLikes.map(([condition, runnable]) => [
106
- (0, base_js_1._coerceToRunnable)(condition),
107
- (0, base_js_1._coerceToRunnable)(runnable),
108
- ]);
109
- const defaultBranch = (0, base_js_1._coerceToRunnable)(branches[branches.length - 1]);
110
- return new this({
111
- branches: coercedBranches,
112
- default: defaultBranch,
113
- });
114
- }
115
- async _invoke(input, config, runManager) {
116
- let result;
117
- for (let i = 0; i < this.branches.length; i += 1) {
118
- const [condition, branchRunnable] = this.branches[i];
119
- const conditionValue = await condition.invoke(input, this._patchConfig(config, runManager?.getChild(`condition:${i + 1}`)));
120
- if (conditionValue) {
121
- result = await branchRunnable.invoke(input, this._patchConfig(config, runManager?.getChild(`branch:${i + 1}`)));
122
- break;
123
- }
124
- }
125
- if (!result) {
126
- result = await this.default.invoke(input, this._patchConfig(config, runManager?.getChild("default")));
127
- }
128
- return result;
129
- }
130
- async invoke(input, config = {}) {
131
- return this._callWithConfig(this._invoke, input, config);
132
- }
133
- }
134
- exports.RunnableBranch = RunnableBranch;
4
+ var runnables_1 = require("langchain-core/runnables");
5
+ Object.defineProperty(exports, "RunnableBranch", { enumerable: true, get: function () { return runnables_1.RunnableBranch; } });
@@ -1,94 +1 @@
1
- import { Runnable, RunnableLike } from "./base.js";
2
- import { RunnableConfig } from "./config.js";
3
- import { CallbackManagerForChainRun } from "../../callbacks/manager.js";
4
- /**
5
- * Type for a branch in the RunnableBranch. It consists of a condition
6
- * runnable and a branch runnable. The condition runnable is used to
7
- * determine whether the branch should be executed, and the branch runnable
8
- * is executed if the condition is true.
9
- */
10
- export type Branch<RunInput, RunOutput> = [
11
- Runnable<RunInput, boolean>,
12
- Runnable<RunInput, RunOutput>
13
- ];
14
- export type BranchLike<RunInput, RunOutput> = [
15
- RunnableLike<RunInput, boolean>,
16
- RunnableLike<RunInput, RunOutput>
17
- ];
18
- /**
19
- * Class that represents a runnable branch. The RunnableBranch is
20
- * initialized with an array of branches and a default branch. When invoked,
21
- * it evaluates the condition of each branch in order and executes the
22
- * corresponding branch if the condition is true. If none of the conditions
23
- * are true, it executes the default branch.
24
- * @example
25
- * ```typescript
26
- * const branch = RunnableBranch.from([
27
- * [
28
- * (x: { topic: string; question: string }) =>
29
- * x.topic.toLowerCase().includes("anthropic"),
30
- * anthropicChain,
31
- * ],
32
- * [
33
- * (x: { topic: string; question: string }) =>
34
- * x.topic.toLowerCase().includes("langchain"),
35
- * langChainChain,
36
- * ],
37
- * generalChain,
38
- * ]);
39
- *
40
- * const fullChain = RunnableSequence.from([
41
- * {
42
- * topic: classificationChain,
43
- * question: (input: { question: string }) => input.question,
44
- * },
45
- * branch,
46
- * ]);
47
- *
48
- * const result = await fullChain.invoke({
49
- * question: "how do I use LangChain?",
50
- * });
51
- * ```
52
- */
53
- export declare class RunnableBranch<RunInput = any, RunOutput = any> extends Runnable<RunInput, RunOutput> {
54
- static lc_name(): string;
55
- lc_namespace: string[];
56
- lc_serializable: boolean;
57
- default: Runnable<RunInput, RunOutput>;
58
- branches: Branch<RunInput, RunOutput>[];
59
- constructor(fields: {
60
- branches: Branch<RunInput, RunOutput>[];
61
- default: Runnable<RunInput, RunOutput>;
62
- });
63
- /**
64
- * Convenience method for instantiating a RunnableBranch from
65
- * RunnableLikes (objects, functions, or Runnables).
66
- *
67
- * Each item in the input except for the last one should be a
68
- * tuple with two items. The first is a "condition" RunnableLike that
69
- * returns "true" if the second RunnableLike in the tuple should run.
70
- *
71
- * The final item in the input should be a RunnableLike that acts as a
72
- * default branch if no other branches match.
73
- *
74
- * @example
75
- * ```ts
76
- * import { RunnableBranch } from "langchain/schema/runnable";
77
- *
78
- * const branch = RunnableBranch.from([
79
- * [(x: number) => x > 0, (x: number) => x + 1],
80
- * [(x: number) => x < 0, (x: number) => x - 1],
81
- * (x: number) => x
82
- * ]);
83
- * ```
84
- * @param branches An array where the every item except the last is a tuple of [condition, runnable]
85
- * pairs. The last item is a default runnable which is invoked if no other condition matches.
86
- * @returns A new RunnableBranch.
87
- */
88
- static from<RunInput = any, RunOutput = any>(branches: [
89
- ...BranchLike<RunInput, RunOutput>[],
90
- RunnableLike<RunInput, RunOutput>
91
- ]): RunnableBranch<RunInput, RunOutput>;
92
- _invoke(input: RunInput, config?: Partial<RunnableConfig>, runManager?: CallbackManagerForChainRun): Promise<RunOutput>;
93
- invoke(input: RunInput, config?: RunnableConfig): Promise<RunOutput>;
94
- }
1
+ export { type Branch, type BranchLike, RunnableBranch, } from "langchain-core/runnables";
@@ -1,130 +1 @@
1
- import { Runnable, _coerceToRunnable } from "./base.js";
2
- /**
3
- * Class that represents a runnable branch. The RunnableBranch is
4
- * initialized with an array of branches and a default branch. When invoked,
5
- * it evaluates the condition of each branch in order and executes the
6
- * corresponding branch if the condition is true. If none of the conditions
7
- * are true, it executes the default branch.
8
- * @example
9
- * ```typescript
10
- * const branch = RunnableBranch.from([
11
- * [
12
- * (x: { topic: string; question: string }) =>
13
- * x.topic.toLowerCase().includes("anthropic"),
14
- * anthropicChain,
15
- * ],
16
- * [
17
- * (x: { topic: string; question: string }) =>
18
- * x.topic.toLowerCase().includes("langchain"),
19
- * langChainChain,
20
- * ],
21
- * generalChain,
22
- * ]);
23
- *
24
- * const fullChain = RunnableSequence.from([
25
- * {
26
- * topic: classificationChain,
27
- * question: (input: { question: string }) => input.question,
28
- * },
29
- * branch,
30
- * ]);
31
- *
32
- * const result = await fullChain.invoke({
33
- * question: "how do I use LangChain?",
34
- * });
35
- * ```
36
- */
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- export class RunnableBranch extends Runnable {
39
- static lc_name() {
40
- return "RunnableBranch";
41
- }
42
- constructor(fields) {
43
- super(fields);
44
- Object.defineProperty(this, "lc_namespace", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: ["langchain", "runnable", "branch"]
49
- });
50
- Object.defineProperty(this, "lc_serializable", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: true
55
- });
56
- Object.defineProperty(this, "default", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: void 0
61
- });
62
- Object.defineProperty(this, "branches", {
63
- enumerable: true,
64
- configurable: true,
65
- writable: true,
66
- value: void 0
67
- });
68
- this.branches = fields.branches;
69
- this.default = fields.default;
70
- }
71
- /**
72
- * Convenience method for instantiating a RunnableBranch from
73
- * RunnableLikes (objects, functions, or Runnables).
74
- *
75
- * Each item in the input except for the last one should be a
76
- * tuple with two items. The first is a "condition" RunnableLike that
77
- * returns "true" if the second RunnableLike in the tuple should run.
78
- *
79
- * The final item in the input should be a RunnableLike that acts as a
80
- * default branch if no other branches match.
81
- *
82
- * @example
83
- * ```ts
84
- * import { RunnableBranch } from "langchain/schema/runnable";
85
- *
86
- * const branch = RunnableBranch.from([
87
- * [(x: number) => x > 0, (x: number) => x + 1],
88
- * [(x: number) => x < 0, (x: number) => x - 1],
89
- * (x: number) => x
90
- * ]);
91
- * ```
92
- * @param branches An array where the every item except the last is a tuple of [condition, runnable]
93
- * pairs. The last item is a default runnable which is invoked if no other condition matches.
94
- * @returns A new RunnableBranch.
95
- */
96
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
- static from(branches) {
98
- if (branches.length < 1) {
99
- throw new Error("RunnableBranch requires at least one branch");
100
- }
101
- const branchLikes = branches.slice(0, -1);
102
- const coercedBranches = branchLikes.map(([condition, runnable]) => [
103
- _coerceToRunnable(condition),
104
- _coerceToRunnable(runnable),
105
- ]);
106
- const defaultBranch = _coerceToRunnable(branches[branches.length - 1]);
107
- return new this({
108
- branches: coercedBranches,
109
- default: defaultBranch,
110
- });
111
- }
112
- async _invoke(input, config, runManager) {
113
- let result;
114
- for (let i = 0; i < this.branches.length; i += 1) {
115
- const [condition, branchRunnable] = this.branches[i];
116
- const conditionValue = await condition.invoke(input, this._patchConfig(config, runManager?.getChild(`condition:${i + 1}`)));
117
- if (conditionValue) {
118
- result = await branchRunnable.invoke(input, this._patchConfig(config, runManager?.getChild(`branch:${i + 1}`)));
119
- break;
120
- }
121
- }
122
- if (!result) {
123
- result = await this.default.invoke(input, this._patchConfig(config, runManager?.getChild("default")));
124
- }
125
- return result;
126
- }
127
- async invoke(input, config = {}) {
128
- return this._callWithConfig(this._invoke, input, config);
129
- }
130
- }
1
+ export { RunnableBranch, } from "langchain-core/runnables";
@@ -1,8 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCallbackMangerForConfig = void 0;
4
- const manager_js_1 = require("../../callbacks/manager.cjs");
5
- async function getCallbackMangerForConfig(config) {
6
- return manager_js_1.CallbackManager.configure(config?.callbacks, undefined, config?.tags, undefined, config?.metadata);
7
- }
8
- exports.getCallbackMangerForConfig = getCallbackMangerForConfig;
@@ -1,3 +1 @@
1
- import { BaseCallbackConfig, CallbackManager } from "../../callbacks/manager.js";
2
- export type RunnableConfig = BaseCallbackConfig;
3
- export declare function getCallbackMangerForConfig(config?: RunnableConfig): Promise<CallbackManager | undefined>;
1
+ export { getCallbackMangerForConfig, RunnableConfig, } from "langchain-core/runnables";
@@ -1,4 +1 @@
1
- import { CallbackManager, } from "../../callbacks/manager.js";
2
- export async function getCallbackMangerForConfig(config) {
3
- return CallbackManager.configure(config?.callbacks, undefined, config?.tags, undefined, config?.metadata);
4
- }
1
+ export {};
@@ -1,18 +1,17 @@
1
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
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RunnableBranch = exports.RouterRunnable = exports.RunnablePassthrough = exports.RunnableWithFallbacks = exports.RunnableLambda = exports.RunnableMap = exports.RunnableSequence = exports.RunnableRetry = exports.RunnableEach = exports.RunnableBinding = exports.Runnable = void 0;
4
- var base_js_1 = require("./base.cjs");
5
- Object.defineProperty(exports, "Runnable", { enumerable: true, get: function () { return base_js_1.Runnable; } });
6
- Object.defineProperty(exports, "RunnableBinding", { enumerable: true, get: function () { return base_js_1.RunnableBinding; } });
7
- Object.defineProperty(exports, "RunnableEach", { enumerable: true, get: function () { return base_js_1.RunnableEach; } });
8
- Object.defineProperty(exports, "RunnableRetry", { enumerable: true, get: function () { return base_js_1.RunnableRetry; } });
9
- Object.defineProperty(exports, "RunnableSequence", { enumerable: true, get: function () { return base_js_1.RunnableSequence; } });
10
- Object.defineProperty(exports, "RunnableMap", { enumerable: true, get: function () { return base_js_1.RunnableMap; } });
11
- Object.defineProperty(exports, "RunnableLambda", { enumerable: true, get: function () { return base_js_1.RunnableLambda; } });
12
- Object.defineProperty(exports, "RunnableWithFallbacks", { enumerable: true, get: function () { return base_js_1.RunnableWithFallbacks; } });
13
- var passthrough_js_1 = require("./passthrough.cjs");
14
- Object.defineProperty(exports, "RunnablePassthrough", { enumerable: true, get: function () { return passthrough_js_1.RunnablePassthrough; } });
15
- var router_js_1 = require("./router.cjs");
16
- Object.defineProperty(exports, "RouterRunnable", { enumerable: true, get: function () { return router_js_1.RouterRunnable; } });
17
- var branch_js_1 = require("./branch.cjs");
18
- Object.defineProperty(exports, "RunnableBranch", { enumerable: true, get: function () { return branch_js_1.RunnableBranch; } });
17
+ __exportStar(require("langchain-core/runnables"), exports);
@@ -1,5 +1 @@
1
- export { type RunnableFunc, type RunnableLike, type RunnableBatchOptions, type RunnableRetryFailedAttemptHandler, Runnable, type RunnableBindingArgs, RunnableBinding, RunnableEach, RunnableRetry, RunnableSequence, RunnableMap, RunnableLambda, RunnableWithFallbacks, } from "./base.js";
2
- export type { RunnableConfig } from "./config.js";
3
- export { RunnablePassthrough } from "./passthrough.js";
4
- export { RouterRunnable } from "./router.js";
5
- export { RunnableBranch, type Branch, type BranchLike } from "./branch.js";
1
+ export * from "langchain-core/runnables";
@@ -1,4 +1 @@
1
- export { Runnable, RunnableBinding, RunnableEach, RunnableRetry, RunnableSequence, RunnableMap, RunnableLambda, RunnableWithFallbacks, } from "./base.js";
2
- export { RunnablePassthrough } from "./passthrough.js";
3
- export { RouterRunnable } from "./router.js";
4
- export { RunnableBranch } from "./branch.js";
1
+ export * from "langchain-core/runnables";
@@ -1,116 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RunnablePassthrough = exports.RunnableAssign = void 0;
4
- const base_js_1 = require("./base.cjs");
5
- /**
6
- * A runnable that assigns key-value pairs to inputs of type `Record<string, unknown>`.
7
- */
8
- class RunnableAssign extends base_js_1.Runnable {
9
- constructor(mapper) {
10
- super();
11
- Object.defineProperty(this, "lc_namespace", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: ["langchain", "schema", "runnable"]
16
- });
17
- Object.defineProperty(this, "mapper", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: void 0
22
- });
23
- this.mapper = mapper;
24
- }
25
- async invoke(input, options) {
26
- const mapperResult = await this.mapper.invoke(input, options);
27
- return {
28
- ...input,
29
- ...mapperResult,
30
- };
31
- }
32
- }
33
- exports.RunnableAssign = RunnableAssign;
34
- /**
35
- * A runnable to passthrough inputs unchanged or with additional keys.
36
- *
37
- * This runnable behaves almost like the identity function, except that it
38
- * can be configured to add additional keys to the output, if the input is
39
- * an object.
40
- *
41
- * The example below demonstrates how to use `RunnablePassthrough to
42
- * passthrough the input from the `.invoke()`
43
- *
44
- * @example
45
- * ```typescript
46
- * const chain = RunnableSequence.from([
47
- * {
48
- * question: new RunnablePassthrough(),
49
- * context: async () => loadContextFromStore(),
50
- * },
51
- * prompt,
52
- * llm,
53
- * outputParser,
54
- * ]);
55
- * const response = await chain.invoke(
56
- * "I can pass a single string instead of an object since I'm using `RunnablePassthrough`."
57
- * );
58
- * ```
59
- */
60
- class RunnablePassthrough extends base_js_1.Runnable {
61
- constructor() {
62
- super(...arguments);
63
- Object.defineProperty(this, "lc_namespace", {
64
- enumerable: true,
65
- configurable: true,
66
- writable: true,
67
- value: ["langchain", "schema", "runnable"]
68
- });
69
- Object.defineProperty(this, "lc_serializable", {
70
- enumerable: true,
71
- configurable: true,
72
- writable: true,
73
- value: true
74
- });
75
- }
76
- static lc_name() {
77
- return "RunnablePassthrough";
78
- }
79
- async invoke(input, options) {
80
- return this._callWithConfig((input) => Promise.resolve(input), input, options);
81
- }
82
- /**
83
- * A runnable that assigns key-value pairs to the input.
84
- *
85
- * The example below shows how you could use it with an inline function.
86
- *
87
- * @example
88
- * ```typescript
89
- * const prompt =
90
- * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}
91
- * Question: {question}
92
- * SQL Query:`);
93
- *
94
- * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`
95
- * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.
96
- * // In this case, we're passing the schema.
97
- * const sqlQueryGeneratorChain = RunnableSequence.from([
98
- * RunnablePassthrough.assign({
99
- * schema: async () => db.getTableInfo(),
100
- * }),
101
- * prompt,
102
- * new ChatOpenAI({}).bind({ stop: ["\nSQLResult:"] }),
103
- * new StringOutputParser(),
104
- * ]);
105
- * const result = await sqlQueryGeneratorChain.invoke({
106
- * question: "How many employees are there?",
107
- * });
108
- * ```
109
- */
110
- static assign(
111
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
- mapping) {
113
- return new RunnableAssign(new base_js_1.RunnableMap({ steps: mapping }));
114
- }
115
- }
116
- exports.RunnablePassthrough = RunnablePassthrough;
4
+ var runnables_1 = require("langchain-core/runnables");
5
+ Object.defineProperty(exports, "RunnableAssign", { enumerable: true, get: function () { return runnables_1.RunnableAssign; } });
6
+ Object.defineProperty(exports, "RunnablePassthrough", { enumerable: true, get: function () { return runnables_1.RunnablePassthrough; } });
@@ -1,72 +1 @@
1
- import { Runnable, RunnableLike, RunnableMap } from "./base.js";
2
- import type { RunnableConfig } from "./config.js";
3
- /**
4
- * A runnable that assigns key-value pairs to inputs of type `Record<string, unknown>`.
5
- */
6
- export declare class RunnableAssign<RunInput extends Record<string, any> = any, RunOutput extends Record<string, any> = any, CallOptions extends RunnableConfig = RunnableConfig> extends Runnable<RunInput, RunOutput> {
7
- lc_namespace: string[];
8
- mapper: RunnableMap<RunInput>;
9
- constructor(mapper: RunnableMap<RunInput>);
10
- invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
11
- }
12
- /**
13
- * A runnable to passthrough inputs unchanged or with additional keys.
14
- *
15
- * This runnable behaves almost like the identity function, except that it
16
- * can be configured to add additional keys to the output, if the input is
17
- * an object.
18
- *
19
- * The example below demonstrates how to use `RunnablePassthrough to
20
- * passthrough the input from the `.invoke()`
21
- *
22
- * @example
23
- * ```typescript
24
- * const chain = RunnableSequence.from([
25
- * {
26
- * question: new RunnablePassthrough(),
27
- * context: async () => loadContextFromStore(),
28
- * },
29
- * prompt,
30
- * llm,
31
- * outputParser,
32
- * ]);
33
- * const response = await chain.invoke(
34
- * "I can pass a single string instead of an object since I'm using `RunnablePassthrough`."
35
- * );
36
- * ```
37
- */
38
- export declare class RunnablePassthrough<RunInput> extends Runnable<RunInput, RunInput> {
39
- static lc_name(): string;
40
- lc_namespace: string[];
41
- lc_serializable: boolean;
42
- invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunInput>;
43
- /**
44
- * A runnable that assigns key-value pairs to the input.
45
- *
46
- * The example below shows how you could use it with an inline function.
47
- *
48
- * @example
49
- * ```typescript
50
- * const prompt =
51
- * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}
52
- * Question: {question}
53
- * SQL Query:`);
54
- *
55
- * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`
56
- * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.
57
- * // In this case, we're passing the schema.
58
- * const sqlQueryGeneratorChain = RunnableSequence.from([
59
- * RunnablePassthrough.assign({
60
- * schema: async () => db.getTableInfo(),
61
- * }),
62
- * prompt,
63
- * new ChatOpenAI({}).bind({ stop: ["\nSQLResult:"] }),
64
- * new StringOutputParser(),
65
- * ]);
66
- * const result = await sqlQueryGeneratorChain.invoke({
67
- * question: "How many employees are there?",
68
- * });
69
- * ```
70
- */
71
- static assign(mapping: Record<string, RunnableLike<Record<string, unknown>, any>>): RunnableAssign<Record<string, unknown>, Record<string, unknown>>;
72
- }
1
+ export { RunnableAssign, RunnablePassthrough } from "langchain-core/runnables";