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
@@ -216,6 +216,22 @@ class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
216
216
  }
217
217
  return documents;
218
218
  }
219
+ /**
220
+ * Asynchronously streams documents from the entire GitHub repository.
221
+ * It is suitable for situations where processing large repositories in a memory-efficient manner is required.
222
+ * @yields Yields a Promise that resolves to a Document object for each file or submodule content found in the repository.
223
+ */
224
+ async *loadAsStream() {
225
+ this.log(`Loading documents from ${this.baseUrl}/${this.owner}/${this.repo}/${this.initialPath}...`);
226
+ yield* await this.processRepoAsStream(this.initialPath);
227
+ if (!this.processSubmodules) {
228
+ return;
229
+ }
230
+ await this.getSubmoduleInfo();
231
+ for (const submoduleInfo of this.submoduleInfos) {
232
+ yield* await this.loadSubmoduleAsStream(submoduleInfo);
233
+ }
234
+ }
219
235
  /**
220
236
  * Loads the information about Git submodules from the repository, if available.
221
237
  */
@@ -323,6 +339,37 @@ class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
323
339
  }).load();
324
340
  }
325
341
  }
342
+ /**
343
+ * Asynchronously processes and streams the contents of a specified submodule in the GitHub repository.
344
+ * @param submoduleInfo the info about the submodule to be loaded
345
+ * @yields Yields a Promise that resolves to a Document object for each file found in the submodule.
346
+ */
347
+ async *loadSubmoduleAsStream(submoduleInfo) {
348
+ if (!submoduleInfo.url.startsWith(this.baseUrl)) {
349
+ this.log(`Ignoring external submodule ${submoduleInfo.url}.`);
350
+ yield* [];
351
+ }
352
+ if (!submoduleInfo.path.startsWith(this.initialPath)) {
353
+ this.log(`Ignoring submodule ${submoduleInfo.url}, as it is not on initial path.`);
354
+ yield* [];
355
+ }
356
+ this.log(`Accessing submodule ${submoduleInfo.name} (${submoduleInfo.url})...`);
357
+ const submoduleLoader = new GithubRepoLoader(submoduleInfo.url, {
358
+ accessToken: this.accessToken,
359
+ baseUrl: this.baseUrl,
360
+ apiUrl: this.apiUrl,
361
+ branch: submoduleInfo.ref,
362
+ recursive: this.recursive,
363
+ processSubmodules: this.processSubmodules,
364
+ unknown: this.unknown,
365
+ ignoreFiles: this.ignoreFiles,
366
+ ignorePaths: this.ignorePaths,
367
+ verbose: this.verbose,
368
+ maxConcurrency: this.maxConcurrency,
369
+ maxRetries: this.maxRetries,
370
+ });
371
+ yield* await submoduleLoader.processRepoAsStream(submoduleInfo.path);
372
+ }
326
373
  /**
327
374
  * Determines whether a file or directory should be ignored based on its
328
375
  * path and type.
@@ -414,6 +461,35 @@ class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
414
461
  return Promise.reject(error);
415
462
  }
416
463
  }
464
+ /**
465
+ * Asynchronously processes the contents of the entire GitHub repository,
466
+ * streaming each file as a Document object.
467
+ * @param path The path of the directory to process.
468
+ * @yields Yields a Promise that resolves to a Document object for each file found in the repository.
469
+ */
470
+ async *processRepoAsStream(path) {
471
+ const files = await this.fetchRepoFiles(path);
472
+ for (const file of files) {
473
+ if (this.shouldIgnore(file.path, file.type)) {
474
+ continue;
475
+ }
476
+ if (file.type === "file") {
477
+ try {
478
+ const fileResponse = await this.fetchFileContentWrapper(file);
479
+ yield new document_js_1.Document({
480
+ pageContent: fileResponse.contents,
481
+ metadata: fileResponse.metadata,
482
+ });
483
+ }
484
+ catch (error) {
485
+ this.handleError(`Failed to fetch file content: ${file.path}, ${error}`);
486
+ }
487
+ }
488
+ else if (this.recursive) {
489
+ yield* await this.processDirectoryAsStream(file.path);
490
+ }
491
+ }
492
+ }
417
493
  /**
418
494
  * Fetches the contents of a directory and maps the file / directory paths
419
495
  * to promises that will fetch the file / directory contents.
@@ -430,6 +506,35 @@ class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
430
506
  return Promise.reject(error);
431
507
  }
432
508
  }
509
+ /**
510
+ * Asynchronously processes the contents of a given directory in the GitHub repository,
511
+ * streaming each file as a Document object.
512
+ * @param path The path of the directory to process.
513
+ * @yields Yields a Promise that resolves to a Document object for each file in the directory.
514
+ */
515
+ async *processDirectoryAsStream(path) {
516
+ const files = await this.fetchRepoFiles(path);
517
+ for (const file of files) {
518
+ if (this.shouldIgnore(file.path, file.type)) {
519
+ continue;
520
+ }
521
+ if (file.type === "file") {
522
+ try {
523
+ const fileResponse = await this.fetchFileContentWrapper(file);
524
+ yield new document_js_1.Document({
525
+ pageContent: fileResponse.contents,
526
+ metadata: fileResponse.metadata,
527
+ });
528
+ }
529
+ catch {
530
+ this.handleError(`Failed to fetch file content: ${file.path}`);
531
+ }
532
+ }
533
+ else if (this.recursive) {
534
+ yield* await this.processDirectoryAsStream(file.path);
535
+ }
536
+ }
537
+ }
433
538
  /**
434
539
  * Fetches the files from a GitHub repository.
435
540
  * If the path denotes a single file, the resulting array contains only one element.
@@ -99,6 +99,12 @@ export declare class GithubRepoLoader extends BaseDocumentLoader implements Gith
99
99
  * @returns A promise that resolves to an array of Document instances.
100
100
  */
101
101
  load(): Promise<Document[]>;
102
+ /**
103
+ * Asynchronously streams documents from the entire GitHub repository.
104
+ * It is suitable for situations where processing large repositories in a memory-efficient manner is required.
105
+ * @yields Yields a Promise that resolves to a Document object for each file or submodule content found in the repository.
106
+ */
107
+ loadAsStream(): AsyncGenerator<Document, void, undefined>;
102
108
  /**
103
109
  * Loads the information about Git submodules from the repository, if available.
104
110
  */
@@ -115,6 +121,12 @@ export declare class GithubRepoLoader extends BaseDocumentLoader implements Gith
115
121
  * @param submoduleInfo the info about the submodule to be loaded
116
122
  */
117
123
  private loadSubmodule;
124
+ /**
125
+ * Asynchronously processes and streams the contents of a specified submodule in the GitHub repository.
126
+ * @param submoduleInfo the info about the submodule to be loaded
127
+ * @yields Yields a Promise that resolves to a Document object for each file found in the submodule.
128
+ */
129
+ private loadSubmoduleAsStream;
118
130
  /**
119
131
  * Determines whether a file or directory should be ignored based on its
120
132
  * path and type.
@@ -137,6 +149,13 @@ export declare class GithubRepoLoader extends BaseDocumentLoader implements Gith
137
149
  * Begins the process of fetching the contents of the repository
138
150
  */
139
151
  private processRepo;
152
+ /**
153
+ * Asynchronously processes the contents of the entire GitHub repository,
154
+ * streaming each file as a Document object.
155
+ * @param path The path of the directory to process.
156
+ * @yields Yields a Promise that resolves to a Document object for each file found in the repository.
157
+ */
158
+ private processRepoAsStream;
140
159
  /**
141
160
  * Fetches the contents of a directory and maps the file / directory paths
142
161
  * to promises that will fetch the file / directory contents.
@@ -144,6 +163,13 @@ export declare class GithubRepoLoader extends BaseDocumentLoader implements Gith
144
163
  * @returns A promise that resolves to an array of promises that will fetch the file / directory contents.
145
164
  */
146
165
  private processDirectory;
166
+ /**
167
+ * Asynchronously processes the contents of a given directory in the GitHub repository,
168
+ * streaming each file as a Document object.
169
+ * @param path The path of the directory to process.
170
+ * @yields Yields a Promise that resolves to a Document object for each file in the directory.
171
+ */
172
+ private processDirectoryAsStream;
147
173
  /**
148
174
  * Fetches the files from a GitHub repository.
149
175
  * If the path denotes a single file, the resulting array contains only one element.
@@ -210,6 +210,22 @@ export class GithubRepoLoader extends BaseDocumentLoader {
210
210
  }
211
211
  return documents;
212
212
  }
213
+ /**
214
+ * Asynchronously streams documents from the entire GitHub repository.
215
+ * It is suitable for situations where processing large repositories in a memory-efficient manner is required.
216
+ * @yields Yields a Promise that resolves to a Document object for each file or submodule content found in the repository.
217
+ */
218
+ async *loadAsStream() {
219
+ this.log(`Loading documents from ${this.baseUrl}/${this.owner}/${this.repo}/${this.initialPath}...`);
220
+ yield* await this.processRepoAsStream(this.initialPath);
221
+ if (!this.processSubmodules) {
222
+ return;
223
+ }
224
+ await this.getSubmoduleInfo();
225
+ for (const submoduleInfo of this.submoduleInfos) {
226
+ yield* await this.loadSubmoduleAsStream(submoduleInfo);
227
+ }
228
+ }
213
229
  /**
214
230
  * Loads the information about Git submodules from the repository, if available.
215
231
  */
@@ -317,6 +333,37 @@ export class GithubRepoLoader extends BaseDocumentLoader {
317
333
  }).load();
318
334
  }
319
335
  }
336
+ /**
337
+ * Asynchronously processes and streams the contents of a specified submodule in the GitHub repository.
338
+ * @param submoduleInfo the info about the submodule to be loaded
339
+ * @yields Yields a Promise that resolves to a Document object for each file found in the submodule.
340
+ */
341
+ async *loadSubmoduleAsStream(submoduleInfo) {
342
+ if (!submoduleInfo.url.startsWith(this.baseUrl)) {
343
+ this.log(`Ignoring external submodule ${submoduleInfo.url}.`);
344
+ yield* [];
345
+ }
346
+ if (!submoduleInfo.path.startsWith(this.initialPath)) {
347
+ this.log(`Ignoring submodule ${submoduleInfo.url}, as it is not on initial path.`);
348
+ yield* [];
349
+ }
350
+ this.log(`Accessing submodule ${submoduleInfo.name} (${submoduleInfo.url})...`);
351
+ const submoduleLoader = new GithubRepoLoader(submoduleInfo.url, {
352
+ accessToken: this.accessToken,
353
+ baseUrl: this.baseUrl,
354
+ apiUrl: this.apiUrl,
355
+ branch: submoduleInfo.ref,
356
+ recursive: this.recursive,
357
+ processSubmodules: this.processSubmodules,
358
+ unknown: this.unknown,
359
+ ignoreFiles: this.ignoreFiles,
360
+ ignorePaths: this.ignorePaths,
361
+ verbose: this.verbose,
362
+ maxConcurrency: this.maxConcurrency,
363
+ maxRetries: this.maxRetries,
364
+ });
365
+ yield* await submoduleLoader.processRepoAsStream(submoduleInfo.path);
366
+ }
320
367
  /**
321
368
  * Determines whether a file or directory should be ignored based on its
322
369
  * path and type.
@@ -408,6 +455,35 @@ export class GithubRepoLoader extends BaseDocumentLoader {
408
455
  return Promise.reject(error);
409
456
  }
410
457
  }
458
+ /**
459
+ * Asynchronously processes the contents of the entire GitHub repository,
460
+ * streaming each file as a Document object.
461
+ * @param path The path of the directory to process.
462
+ * @yields Yields a Promise that resolves to a Document object for each file found in the repository.
463
+ */
464
+ async *processRepoAsStream(path) {
465
+ const files = await this.fetchRepoFiles(path);
466
+ for (const file of files) {
467
+ if (this.shouldIgnore(file.path, file.type)) {
468
+ continue;
469
+ }
470
+ if (file.type === "file") {
471
+ try {
472
+ const fileResponse = await this.fetchFileContentWrapper(file);
473
+ yield new Document({
474
+ pageContent: fileResponse.contents,
475
+ metadata: fileResponse.metadata,
476
+ });
477
+ }
478
+ catch (error) {
479
+ this.handleError(`Failed to fetch file content: ${file.path}, ${error}`);
480
+ }
481
+ }
482
+ else if (this.recursive) {
483
+ yield* await this.processDirectoryAsStream(file.path);
484
+ }
485
+ }
486
+ }
411
487
  /**
412
488
  * Fetches the contents of a directory and maps the file / directory paths
413
489
  * to promises that will fetch the file / directory contents.
@@ -424,6 +500,35 @@ export class GithubRepoLoader extends BaseDocumentLoader {
424
500
  return Promise.reject(error);
425
501
  }
426
502
  }
503
+ /**
504
+ * Asynchronously processes the contents of a given directory in the GitHub repository,
505
+ * streaming each file as a Document object.
506
+ * @param path The path of the directory to process.
507
+ * @yields Yields a Promise that resolves to a Document object for each file in the directory.
508
+ */
509
+ async *processDirectoryAsStream(path) {
510
+ const files = await this.fetchRepoFiles(path);
511
+ for (const file of files) {
512
+ if (this.shouldIgnore(file.path, file.type)) {
513
+ continue;
514
+ }
515
+ if (file.type === "file") {
516
+ try {
517
+ const fileResponse = await this.fetchFileContentWrapper(file);
518
+ yield new Document({
519
+ pageContent: fileResponse.contents,
520
+ metadata: fileResponse.metadata,
521
+ });
522
+ }
523
+ catch {
524
+ this.handleError(`Failed to fetch file content: ${file.path}`);
525
+ }
526
+ }
527
+ else if (this.recursive) {
528
+ yield* await this.processDirectoryAsStream(file.path);
529
+ }
530
+ }
531
+ }
427
532
  /**
428
533
  * Fetches the files from a GitHub repository.
429
534
  * If the path denotes a single file, the resulting array contains only one element.
@@ -70,5 +70,5 @@ export declare class S3Loader extends BaseDocumentLoader {
70
70
  * and then uses the UnstructuredLoader to load the file as a document.
71
71
  * @returns An array of Document objects representing the loaded documents.
72
72
  */
73
- load(): Promise<import("../../document.js").Document<Record<string, any>>[]>;
73
+ load(): Promise<import("langchain-core/documents").Document<Record<string, any>>[]>;
74
74
  }
@@ -1,24 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Embeddings = void 0;
4
- const async_caller_js_1 = require("../util/async_caller.cjs");
5
- /**
6
- * An abstract class that provides methods for embedding documents and
7
- * queries using LangChain.
8
- */
9
- class Embeddings {
10
- constructor(params) {
11
- /**
12
- * The async caller should be used by subclasses to make any async calls,
13
- * which will thus benefit from the concurrency and retry logic.
14
- */
15
- Object.defineProperty(this, "caller", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: void 0
20
- });
21
- this.caller = new async_caller_js_1.AsyncCaller(params ?? {});
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]; } };
22
7
  }
23
- }
24
- exports.Embeddings = Embeddings;
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("langchain-core/embeddings"), exports);
@@ -1,33 +1 @@
1
- import { AsyncCaller, AsyncCallerParams } from "../util/async_caller.js";
2
- /**
3
- * The parameters required to initialize an instance of the Embeddings
4
- * class.
5
- */
6
- export type EmbeddingsParams = AsyncCallerParams;
7
- /**
8
- * An abstract class that provides methods for embedding documents and
9
- * queries using LangChain.
10
- */
11
- export declare abstract class Embeddings {
12
- /**
13
- * The async caller should be used by subclasses to make any async calls,
14
- * which will thus benefit from the concurrency and retry logic.
15
- */
16
- caller: AsyncCaller;
17
- constructor(params: EmbeddingsParams);
18
- /**
19
- * An abstract method that takes an array of documents as input and
20
- * returns a promise that resolves to an array of vectors for each
21
- * document.
22
- * @param documents An array of documents to be embedded.
23
- * @returns A promise that resolves to an array of vectors for each document.
24
- */
25
- abstract embedDocuments(documents: string[]): Promise<number[][]>;
26
- /**
27
- * An abstract method that takes a single document as input and returns a
28
- * promise that resolves to a vector for the query document.
29
- * @param document A single document to be embedded.
30
- * @returns A promise that resolves to a vector for the query document.
31
- */
32
- abstract embedQuery(document: string): Promise<number[]>;
33
- }
1
+ export * from "langchain-core/embeddings";
@@ -1,20 +1 @@
1
- import { AsyncCaller } from "../util/async_caller.js";
2
- /**
3
- * An abstract class that provides methods for embedding documents and
4
- * queries using LangChain.
5
- */
6
- export class Embeddings {
7
- constructor(params) {
8
- /**
9
- * The async caller should be used by subclasses to make any async calls,
10
- * which will thus benefit from the concurrency and retry logic.
11
- */
12
- Object.defineProperty(this, "caller", {
13
- enumerable: true,
14
- configurable: true,
15
- writable: true,
16
- value: void 0
17
- });
18
- this.caller = new AsyncCaller(params ?? {});
19
- }
20
- }
1
+ export * from "langchain-core/embeddings";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CacheBackedEmbeddings = void 0;
4
- const hash_js_1 = require("../util/js-sha1/hash.cjs");
4
+ const hash_1 = require("langchain-core/utils/hash");
5
5
  const encoder_backed_js_1 = require("../storage/encoder_backed.cjs");
6
6
  const base_js_1 = require("./base.cjs");
7
7
  /**
@@ -130,7 +130,7 @@ class CacheBackedEmbeddings extends base_js_1.Embeddings {
130
130
  const decoder = new TextDecoder();
131
131
  const encoderBackedStore = new encoder_backed_js_1.EncoderBackedStore({
132
132
  store: documentEmbeddingStore,
133
- keyEncoder: (key) => (options?.namespace ?? "") + (0, hash_js_1.insecureHash)(key),
133
+ keyEncoder: (key) => (options?.namespace ?? "") + (0, hash_1.insecureHash)(key),
134
134
  valueSerializer: (value) => encoder.encode(JSON.stringify(value)),
135
135
  valueDeserializer: (serializedValue) => JSON.parse(decoder.decode(serializedValue)),
136
136
  });
@@ -1,4 +1,4 @@
1
- import { insecureHash } from "../util/js-sha1/hash.js";
1
+ import { insecureHash } from "langchain-core/utils/hash";
2
2
  import { EncoderBackedStore } from "../storage/encoder_backed.js";
3
3
  import { Embeddings } from "./base.js";
4
4
  /**
@@ -27,7 +27,7 @@ export declare class TrajectoryEvalChain extends AgentTrajectoryEvaluator {
27
27
  requiresInput: boolean;
28
28
  requiresReference: boolean;
29
29
  outputParser: TrajectoryOutputParser;
30
- static resolveTrajectoryPrompt(prompt?: BasePromptTemplate | undefined, agentTools?: StructuredTool[]): import("../../prompts/chat.js").ChatPromptTemplate<any, any> | BasePromptTemplate<any, import("../../schema/index.js").BasePromptValue, any>;
30
+ static resolveTrajectoryPrompt(prompt?: BasePromptTemplate | undefined, agentTools?: StructuredTool[]): BasePromptTemplate<any, import("../../schema/index.js").BasePromptValue, any> | import("../../prompts/index.js").ChatPromptTemplate<any, any>;
31
31
  /**
32
32
  * Get the description of the agent tools.
33
33
  *
@@ -1,12 +1,12 @@
1
1
  import { PromptTemplate } from "../../prompts/index.js";
2
2
  export declare const CRITERIA_PROMPT: PromptTemplate<{
3
- output: any;
4
3
  input: any;
4
+ output: any;
5
5
  criteria: any;
6
6
  }, any>;
7
7
  export declare const PROMPT_WITH_REFERENCES: PromptTemplate<{
8
- output: any;
9
8
  input: any;
9
+ output: any;
10
10
  criteria: any;
11
11
  reference: any;
12
12
  }, any>;
@@ -1,11 +1,11 @@
1
1
  import { PromptTemplate } from "../../prompts/prompt.js";
2
2
  export declare const QA_PROMPT: PromptTemplate<{
3
- query: any;
4
3
  answer: any;
4
+ query: any;
5
5
  result: any;
6
6
  }, any>;
7
7
  export declare const SQL_PROMPT: PromptTemplate<{
8
- query: any;
9
8
  answer: any;
9
+ query: any;
10
10
  result: any;
11
11
  }, any>;
@@ -118,7 +118,7 @@ export declare class MakerSuitePrompt {
118
118
  * will have the parameters (model name, temperature, etc) from those in
119
119
  * MakerSuite.
120
120
  */
121
- toChain(): import("../../../schema/runnable/base.js").RunnableSequence<any, any>;
121
+ toChain(): import("../../../schema/runnable/index.js").RunnableSequence<any, any>;
122
122
  }
123
123
  interface DriveFileReadParams extends GoogleVertexAIConnectionParams<GoogleAuthOptions> {
124
124
  fileId: string;
@@ -10,4 +10,4 @@ export declare const DEFAULT_STEP_EXECUTOR_HUMAN_CHAT_MESSAGE_TEMPLATE = "Previo
10
10
  * @param tools the tools available to the `planner`
11
11
  * @returns
12
12
  */
13
- export declare const getPlannerChatPrompt: (tools: Tool[] | DynamicStructuredTool[]) => Promise<ChatPromptTemplate<import("../../schema/index.js").InputValues<string>, any>>;
13
+ export declare const getPlannerChatPrompt: (tools: Tool[] | DynamicStructuredTool[]) => Promise<ChatPromptTemplate<import("langchain-core/utils/types").InputValues<string>, any>>;