langchain 0.0.196 → 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 (136) 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 +4 -4
  6. package/dist/base_language/count_tokens.d.ts +1 -1
  7. package/dist/base_language/count_tokens.js +1 -1
  8. package/dist/base_language/index.cjs +3 -3
  9. package/dist/base_language/index.d.ts +1 -1
  10. package/dist/base_language/index.js +1 -1
  11. package/dist/cache/base.cjs +1 -1
  12. package/dist/cache/base.d.ts +1 -1
  13. package/dist/cache/base.js +1 -1
  14. package/dist/cache/index.cjs +2 -2
  15. package/dist/cache/index.d.ts +1 -1
  16. package/dist/cache/index.js +1 -1
  17. package/dist/callbacks/handlers/console.cjs +1 -1
  18. package/dist/callbacks/handlers/console.d.ts +1 -1
  19. package/dist/callbacks/handlers/console.js +1 -1
  20. package/dist/callbacks/handlers/initialize.cjs +1 -1
  21. package/dist/callbacks/handlers/initialize.d.ts +1 -1
  22. package/dist/callbacks/handlers/initialize.js +1 -1
  23. package/dist/callbacks/handlers/log_stream.cjs +1 -1
  24. package/dist/callbacks/handlers/log_stream.d.ts +1 -1
  25. package/dist/callbacks/handlers/log_stream.js +1 -1
  26. package/dist/callbacks/handlers/run_collector.cjs +1 -1
  27. package/dist/callbacks/handlers/run_collector.d.ts +1 -1
  28. package/dist/callbacks/handlers/run_collector.js +1 -1
  29. package/dist/callbacks/handlers/tracer.cjs +1 -1
  30. package/dist/callbacks/handlers/tracer.d.ts +1 -1
  31. package/dist/callbacks/handlers/tracer.js +1 -1
  32. package/dist/callbacks/handlers/tracer_langchain.cjs +1 -1
  33. package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -1
  34. package/dist/callbacks/handlers/tracer_langchain.js +1 -1
  35. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +1 -1
  36. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -1
  37. package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -1
  38. package/dist/chains/openai_functions/structured_output.cjs +1 -1
  39. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  40. package/dist/chains/openai_functions/structured_output.js +1 -1
  41. package/dist/chat_models/anthropic.cjs +15 -348
  42. package/dist/chat_models/anthropic.d.ts +1 -156
  43. package/dist/chat_models/anthropic.js +1 -346
  44. package/dist/chat_models/base.cjs +1 -1
  45. package/dist/chat_models/base.d.ts +1 -1
  46. package/dist/chat_models/base.js +1 -1
  47. package/dist/chat_models/bedrock/web.cjs +21 -1
  48. package/dist/chat_models/bedrock/web.d.ts +1 -1
  49. package/dist/chat_models/bedrock/web.js +21 -1
  50. package/dist/document.cjs +2 -2
  51. package/dist/document.d.ts +1 -1
  52. package/dist/document.js +1 -1
  53. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
  54. package/dist/document_loaders/web/github.cjs +105 -0
  55. package/dist/document_loaders/web/github.d.ts +26 -0
  56. package/dist/document_loaders/web/github.js +105 -0
  57. package/dist/document_loaders/web/s3.d.ts +1 -1
  58. package/dist/embeddings/base.cjs +1 -1
  59. package/dist/embeddings/base.d.ts +1 -1
  60. package/dist/embeddings/base.js +1 -1
  61. package/dist/embeddings/cache_backed.cjs +1 -1
  62. package/dist/embeddings/cache_backed.js +1 -1
  63. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  64. package/dist/llms/base.cjs +1 -1
  65. package/dist/llms/base.d.ts +1 -1
  66. package/dist/llms/base.js +1 -1
  67. package/dist/llms/bedrock/web.cjs +21 -1
  68. package/dist/llms/bedrock/web.d.ts +1 -1
  69. package/dist/llms/bedrock/web.js +21 -1
  70. package/dist/memory/base.cjs +2 -2
  71. package/dist/memory/base.d.ts +2 -2
  72. package/dist/memory/base.js +2 -2
  73. package/dist/output_parsers/list.cjs +4 -122
  74. package/dist/output_parsers/list.d.ts +1 -57
  75. package/dist/output_parsers/list.js +1 -119
  76. package/dist/output_parsers/openai_functions.cjs +1 -1
  77. package/dist/output_parsers/openai_functions.d.ts +1 -1
  78. package/dist/output_parsers/openai_functions.js +1 -1
  79. package/dist/prompts/base.cjs +8 -8
  80. package/dist/prompts/base.d.ts +3 -3
  81. package/dist/prompts/base.js +3 -3
  82. package/dist/prompts/chat.cjs +13 -15
  83. package/dist/prompts/chat.d.ts +2 -1
  84. package/dist/prompts/chat.js +2 -1
  85. package/dist/prompts/few_shot.cjs +4 -15
  86. package/dist/prompts/few_shot.d.ts +1 -1
  87. package/dist/prompts/few_shot.js +1 -1
  88. package/dist/prompts/index.cjs +2 -2
  89. package/dist/prompts/index.d.ts +1 -1
  90. package/dist/prompts/index.js +1 -1
  91. package/dist/prompts/pipeline.cjs +3 -15
  92. package/dist/prompts/pipeline.d.ts +1 -1
  93. package/dist/prompts/pipeline.js +1 -1
  94. package/dist/prompts/prompt.cjs +3 -15
  95. package/dist/prompts/prompt.d.ts +1 -1
  96. package/dist/prompts/prompt.js +1 -1
  97. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +3 -15
  98. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -1
  99. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -1
  100. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +1 -1
  101. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -1
  102. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -1
  103. package/dist/prompts/selectors/conditional.cjs +6 -15
  104. package/dist/prompts/selectors/conditional.d.ts +1 -1
  105. package/dist/prompts/selectors/conditional.js +1 -1
  106. package/dist/prompts/serde.cjs +0 -15
  107. package/dist/prompts/serde.d.ts +1 -1
  108. package/dist/prompts/serde.js +1 -1
  109. package/dist/prompts/template.cjs +9 -15
  110. package/dist/prompts/template.d.ts +1 -1
  111. package/dist/prompts/template.js +1 -1
  112. package/dist/schema/document.cjs +3 -3
  113. package/dist/schema/document.d.ts +1 -1
  114. package/dist/schema/document.js +1 -1
  115. package/dist/schema/index.cjs +12 -12
  116. package/dist/schema/index.d.ts +10 -10
  117. package/dist/schema/index.js +7 -7
  118. package/dist/schema/output_parser.cjs +1 -1
  119. package/dist/schema/output_parser.d.ts +1 -1
  120. package/dist/schema/output_parser.js +1 -1
  121. package/dist/schema/retriever.cjs +1 -1
  122. package/dist/schema/retriever.d.ts +1 -1
  123. package/dist/schema/retriever.js +1 -1
  124. package/dist/schema/storage.cjs +1 -1
  125. package/dist/schema/storage.d.ts +1 -1
  126. package/dist/schema/storage.js +1 -1
  127. package/dist/util/async_caller.cjs +1 -1
  128. package/dist/util/async_caller.d.ts +1 -1
  129. package/dist/util/async_caller.js +1 -1
  130. package/dist/vectorstores/momento_vector_index.cjs +39 -0
  131. package/dist/vectorstores/momento_vector_index.d.ts +17 -1
  132. package/dist/vectorstores/momento_vector_index.js +40 -1
  133. package/dist/vectorstores/mongodb_atlas.cjs +22 -2
  134. package/dist/vectorstores/mongodb_atlas.d.ts +13 -0
  135. package/dist/vectorstores/mongodb_atlas.js +22 -2
  136. package/package.json +9 -8
@@ -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("langchain-core/schema/document").Document<Record<string, any>>[]>;
73
+ load(): Promise<import("langchain-core/documents").Document<Record<string, any>>[]>;
74
74
  }
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("langchain-core/schema/embeddings"), exports);
17
+ __exportStar(require("langchain-core/embeddings"), exports);
@@ -1 +1 @@
1
- export * from "langchain-core/schema/embeddings";
1
+ export * from "langchain-core/embeddings";
@@ -1 +1 @@
1
- export * from "langchain-core/schema/embeddings";
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_1 = require("langchain-core/util/hash");
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
  /**
@@ -1,4 +1,4 @@
1
- import { insecureHash } from "langchain-core/util/hash";
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
  /**
@@ -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("langchain-core/schema").InputValues<string>, any>>;
13
+ export declare const getPlannerChatPrompt: (tools: Tool[] | DynamicStructuredTool[]) => Promise<ChatPromptTemplate<import("langchain-core/utils/types").InputValues<string>, any>>;
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("langchain-core/llm"), exports);
17
+ __exportStar(require("langchain-core/language_models/llms"), exports);
@@ -1 +1 @@
1
- export * from "langchain-core/llm";
1
+ export * from "langchain-core/language_models/llms";
package/dist/llms/base.js CHANGED
@@ -1 +1 @@
1
- export * from "langchain-core/llm";
1
+ export * from "langchain-core/language_models/llms";
@@ -278,11 +278,31 @@ class Bedrock extends base_js_1.LLM {
278
278
  }
279
279
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
280
280
  _readChunks(reader) {
281
+ function _concatChunks(a, b) {
282
+ const newBuffer = new Uint8Array(a.length + b.length);
283
+ newBuffer.set(a);
284
+ newBuffer.set(b, a.length);
285
+ return newBuffer;
286
+ }
287
+ function getMessageLength(buffer) {
288
+ if (buffer.byteLength === 0)
289
+ return 0;
290
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
291
+ return view.getUint32(0, false);
292
+ }
281
293
  return {
282
294
  async *[Symbol.asyncIterator]() {
283
295
  let readResult = await reader.read();
296
+ let buffer = new Uint8Array(0);
284
297
  while (!readResult.done) {
285
- yield readResult.value;
298
+ const chunk = readResult.value;
299
+ buffer = _concatChunks(buffer, chunk);
300
+ let messageLength = getMessageLength(buffer);
301
+ while (buffer.byteLength > 0 && buffer.byteLength >= messageLength) {
302
+ yield buffer.slice(0, messageLength);
303
+ buffer = buffer.slice(messageLength);
304
+ messageLength = getMessageLength(buffer);
305
+ }
286
306
  readResult = await reader.read();
287
307
  }
288
308
  },
@@ -61,6 +61,6 @@ export declare class Bedrock extends LLM implements BaseBedrockInput {
61
61
  };
62
62
  _streamResponseChunks(prompt: string, options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;
63
63
  _readChunks(reader: any): {
64
- [Symbol.asyncIterator](): AsyncGenerator<any, void, unknown>;
64
+ [Symbol.asyncIterator](): AsyncGenerator<Uint8Array, void, unknown>;
65
65
  };
66
66
  }
@@ -275,11 +275,31 @@ export class Bedrock extends LLM {
275
275
  }
276
276
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
277
277
  _readChunks(reader) {
278
+ function _concatChunks(a, b) {
279
+ const newBuffer = new Uint8Array(a.length + b.length);
280
+ newBuffer.set(a);
281
+ newBuffer.set(b, a.length);
282
+ return newBuffer;
283
+ }
284
+ function getMessageLength(buffer) {
285
+ if (buffer.byteLength === 0)
286
+ return 0;
287
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
288
+ return view.getUint32(0, false);
289
+ }
278
290
  return {
279
291
  async *[Symbol.asyncIterator]() {
280
292
  let readResult = await reader.read();
293
+ let buffer = new Uint8Array(0);
281
294
  while (!readResult.done) {
282
- yield readResult.value;
295
+ const chunk = readResult.value;
296
+ buffer = _concatChunks(buffer, chunk);
297
+ let messageLength = getMessageLength(buffer);
298
+ while (buffer.byteLength > 0 && buffer.byteLength >= messageLength) {
299
+ yield buffer.slice(0, messageLength);
300
+ buffer = buffer.slice(messageLength);
301
+ messageLength = getMessageLength(buffer);
302
+ }
283
303
  readResult = await reader.read();
284
304
  }
285
305
  },
@@ -15,6 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.getBufferString = void 0;
18
- __exportStar(require("langchain-core/schema/memory"), exports);
19
- var messages_1 = require("langchain-core/schema/messages");
18
+ __exportStar(require("langchain-core/memory"), exports);
19
+ var messages_1 = require("langchain-core/messages");
20
20
  Object.defineProperty(exports, "getBufferString", { enumerable: true, get: function () { return messages_1.getBufferString; } });
@@ -1,2 +1,2 @@
1
- export * from "langchain-core/schema/memory";
2
- export { getBufferString } from "langchain-core/schema/messages";
1
+ export * from "langchain-core/memory";
2
+ export { getBufferString } from "langchain-core/messages";
@@ -1,2 +1,2 @@
1
- export * from "langchain-core/schema/memory";
2
- export { getBufferString } from "langchain-core/schema/messages";
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,7 +1,7 @@
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/util/json_patch");
4
+ const json_patch_1 = require("langchain-core/utils/json_patch");
5
5
  const output_parser_js_1 = require("../schema/output_parser.cjs");
6
6
  const json_js_1 = require("./json.cjs");
7
7
  /**
@@ -1,5 +1,5 @@
1
1
  import { JsonSchema7ObjectType } from "zod-to-json-schema/src/parsers/object.js";
2
- import { type Operation as JSONPatchOperation } from "langchain-core/util/json_patch";
2
+ import { type Operation as JSONPatchOperation } from "langchain-core/utils/json_patch";
3
3
  import { ChatGeneration, Generation } from "../schema/index.js";
4
4
  import { Optional } from "../types/type-utils.js";
5
5
  import { BaseCumulativeTransformOutputParser, type BaseCumulativeTransformOutputParserInput, BaseLLMOutputParser } from "../schema/output_parser.js";
@@ -1,4 +1,4 @@
1
- import { compare, } from "langchain-core/util/json_patch";
1
+ import { compare, } from "langchain-core/utils/json_patch";
2
2
  import { BaseCumulativeTransformOutputParser, BaseLLMOutputParser, } from "../schema/output_parser.js";
3
3
  import { parsePartialJson } from "./json.js";
4
4
  /**
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseExampleSelector = exports.BasePromptTemplate = exports.BaseStringPromptTemplate = exports.StringPromptValue = void 0;
4
- var base_1 = require("langchain-core/prompts/base");
5
- Object.defineProperty(exports, "StringPromptValue", { enumerable: true, get: function () { return base_1.StringPromptValue; } });
6
- Object.defineProperty(exports, "BaseStringPromptTemplate", { enumerable: true, get: function () { return base_1.BaseStringPromptTemplate; } });
7
- var prompt_template_1 = require("langchain-core/schema/prompt_template");
8
- Object.defineProperty(exports, "BasePromptTemplate", { enumerable: true, get: function () { return prompt_template_1.BasePromptTemplate; } });
9
- var base_2 = require("langchain-core/prompts/example_selector/base");
10
- Object.defineProperty(exports, "BaseExampleSelector", { enumerable: true, get: function () { return base_2.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; } });