langchain 0.0.145 → 0.0.147

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 (120) hide show
  1. package/dist/base_language/index.cjs +2 -2
  2. package/dist/base_language/index.d.ts +2 -1
  3. package/dist/base_language/index.js +1 -1
  4. package/dist/chains/api/api_chain.d.ts +1 -1
  5. package/dist/chains/base.d.ts +1 -1
  6. package/dist/chains/openai_functions/extraction.d.ts +1 -1
  7. package/dist/chains/openai_functions/openapi.cjs +32 -27
  8. package/dist/chains/openai_functions/openapi.d.ts +10 -1
  9. package/dist/chains/openai_functions/openapi.js +31 -27
  10. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  11. package/dist/chains/openai_functions/tagging.d.ts +1 -1
  12. package/dist/chat_models/anthropic.d.ts +2 -2
  13. package/dist/chat_models/base.d.ts +1 -1
  14. package/dist/chat_models/openai.cjs +1 -1
  15. package/dist/chat_models/openai.js +1 -1
  16. package/dist/experimental/llms/bittensor.cjs +141 -0
  17. package/dist/experimental/llms/bittensor.d.ts +33 -0
  18. package/dist/experimental/llms/bittensor.js +137 -0
  19. package/dist/hub.cjs +14 -0
  20. package/dist/hub.d.ts +15 -1
  21. package/dist/hub.js +14 -0
  22. package/dist/llms/base.d.ts +1 -1
  23. package/dist/llms/openai-chat.cjs +1 -1
  24. package/dist/llms/openai-chat.js +1 -1
  25. package/dist/llms/openai.cjs +1 -1
  26. package/dist/llms/openai.js +1 -1
  27. package/dist/load/import_constants.cjs +2 -0
  28. package/dist/load/import_constants.js +2 -0
  29. package/dist/load/import_map.cjs +1 -1
  30. package/dist/load/import_map.d.ts +1 -1
  31. package/dist/load/import_map.js +1 -1
  32. package/dist/load/index.cjs +2 -1
  33. package/dist/load/index.js +2 -1
  34. package/dist/prompts/base.cjs +2 -2
  35. package/dist/prompts/base.d.ts +1 -1
  36. package/dist/prompts/base.js +1 -1
  37. package/dist/prompts/chat.cjs +2 -2
  38. package/dist/prompts/chat.d.ts +1 -1
  39. package/dist/prompts/chat.js +1 -1
  40. package/dist/schema/document.cjs +2 -2
  41. package/dist/schema/document.d.ts +1 -1
  42. package/dist/schema/document.js +1 -1
  43. package/dist/schema/index.cjs +5 -22
  44. package/dist/schema/index.d.ts +1 -5
  45. package/dist/schema/index.js +5 -22
  46. package/dist/schema/output_parser.cjs +2 -2
  47. package/dist/schema/output_parser.d.ts +2 -1
  48. package/dist/schema/output_parser.js +1 -1
  49. package/dist/schema/retriever.cjs +2 -2
  50. package/dist/schema/retriever.d.ts +2 -1
  51. package/dist/schema/retriever.js +1 -1
  52. package/dist/schema/runnable/config.cjs +8 -0
  53. package/dist/schema/runnable/config.d.ts +3 -0
  54. package/dist/schema/runnable/config.js +4 -0
  55. package/dist/schema/{runnable.cjs → runnable/index.cjs} +290 -101
  56. package/dist/schema/{runnable.d.ts → runnable/index.d.ts} +127 -41
  57. package/dist/schema/{runnable.js → runnable/index.js} +284 -99
  58. package/dist/tools/base.d.ts +1 -1
  59. package/dist/types/googlevertexai-types.d.ts +1 -1
  60. package/dist/util/async_caller.cjs +35 -25
  61. package/dist/util/async_caller.d.ts +8 -0
  62. package/dist/util/async_caller.js +35 -25
  63. package/dist/vectorstores/pinecone.cjs +30 -22
  64. package/dist/vectorstores/pinecone.d.ts +3 -1
  65. package/dist/vectorstores/pinecone.js +30 -22
  66. package/dist/vectorstores/vectara.cjs +20 -23
  67. package/dist/vectorstores/vectara.d.ts +9 -2
  68. package/dist/vectorstores/vectara.js +20 -23
  69. package/dist/vectorstores/voy.cjs +158 -0
  70. package/dist/vectorstores/voy.d.ts +73 -0
  71. package/dist/vectorstores/voy.js +154 -0
  72. package/experimental/llms/bittensor.cjs +1 -0
  73. package/experimental/llms/bittensor.d.ts +1 -0
  74. package/experimental/llms/bittensor.js +1 -0
  75. package/package.json +24 -68
  76. package/schema/runnable.cjs +1 -1
  77. package/schema/runnable.d.ts +1 -1
  78. package/schema/runnable.js +1 -1
  79. package/vectorstores/voy.cjs +1 -0
  80. package/vectorstores/voy.d.ts +1 -0
  81. package/vectorstores/voy.js +1 -0
  82. package/chat_models.cjs +0 -1
  83. package/chat_models.d.ts +0 -1
  84. package/chat_models.js +0 -1
  85. package/dist/chat_models/index.cjs +0 -11
  86. package/dist/chat_models/index.d.ts +0 -3
  87. package/dist/chat_models/index.js +0 -4
  88. package/dist/document_loaders/index.cjs +0 -40
  89. package/dist/document_loaders/index.d.ts +0 -18
  90. package/dist/document_loaders/index.js +0 -18
  91. package/dist/embeddings/index.cjs +0 -12
  92. package/dist/embeddings/index.d.ts +0 -4
  93. package/dist/embeddings/index.js +0 -5
  94. package/dist/index.cjs +0 -12
  95. package/dist/index.d.ts +0 -3
  96. package/dist/index.js +0 -4
  97. package/dist/llms/index.cjs +0 -18
  98. package/dist/llms/index.d.ts +0 -6
  99. package/dist/llms/index.js +0 -7
  100. package/dist/retrievers/index.cjs +0 -14
  101. package/dist/retrievers/index.d.ts +0 -5
  102. package/dist/retrievers/index.js +0 -6
  103. package/dist/vectorstores/index.cjs +0 -17
  104. package/dist/vectorstores/index.d.ts +0 -6
  105. package/dist/vectorstores/index.js +0 -7
  106. package/document_loaders.cjs +0 -1
  107. package/document_loaders.d.ts +0 -1
  108. package/document_loaders.js +0 -1
  109. package/embeddings.cjs +0 -1
  110. package/embeddings.d.ts +0 -1
  111. package/embeddings.js +0 -1
  112. package/llms.cjs +0 -1
  113. package/llms.d.ts +0 -1
  114. package/llms.js +0 -1
  115. package/retrievers.cjs +0 -1
  116. package/retrievers.d.ts +0 -1
  117. package/retrievers.js +0 -1
  118. package/vectorstores.cjs +0 -1
  119. package/vectorstores.d.ts +0 -1
  120. package/vectorstores.js +0 -1
package/dist/hub.d.ts CHANGED
@@ -1,4 +1,18 @@
1
1
  import { ClientConfiguration, HubPushOptions } from "langchainhub";
2
- import { Runnable } from "./schema/runnable.js";
2
+ import { Runnable } from "./schema/runnable/index.js";
3
+ /**
4
+ * Push a prompt to the hub.
5
+ * If the specified repo doesn't already exist, it will be created.
6
+ * @param repoFullName The full name of the repo.
7
+ * @param runnable The prompt to push.
8
+ * @param options
9
+ * @returns The URL of the newly pushed prompt in the hub.
10
+ */
3
11
  export declare function push(repoFullName: string, runnable: Runnable, options?: HubPushOptions & ClientConfiguration): Promise<string>;
12
+ /**
13
+ * Pull a prompt from the hub.
14
+ * @param ownerRepoCommit The name of the repo containing the prompt, as well as an optional commit hash separated by a slash.
15
+ * @param options
16
+ * @returns
17
+ */
4
18
  export declare function pull<T extends Runnable>(ownerRepoCommit: string, options?: ClientConfiguration): Promise<T>;
package/dist/hub.js CHANGED
@@ -1,9 +1,23 @@
1
1
  import { Client } from "langchainhub";
2
2
  import { load } from "./load/index.js";
3
+ /**
4
+ * Push a prompt to the hub.
5
+ * If the specified repo doesn't already exist, it will be created.
6
+ * @param repoFullName The full name of the repo.
7
+ * @param runnable The prompt to push.
8
+ * @param options
9
+ * @returns The URL of the newly pushed prompt in the hub.
10
+ */
3
11
  export async function push(repoFullName, runnable, options) {
4
12
  const client = new Client(options);
5
13
  return client.push(repoFullName, JSON.stringify(runnable), options);
6
14
  }
15
+ /**
16
+ * Pull a prompt from the hub.
17
+ * @param ownerRepoCommit The name of the repo containing the prompt, as well as an optional commit hash separated by a slash.
18
+ * @param options
19
+ * @returns
20
+ */
7
21
  export async function pull(ownerRepoCommit, options) {
8
22
  const client = new Client(options);
9
23
  const result = await client.pull(ownerRepoCommit);
@@ -1,7 +1,7 @@
1
1
  import { BaseCache, BaseMessage, BasePromptValue, GenerationChunk, LLMResult } from "../schema/index.js";
2
2
  import { BaseLanguageModel, BaseLanguageModelCallOptions, BaseLanguageModelInput, BaseLanguageModelParams } from "../base_language/index.js";
3
3
  import { BaseCallbackConfig, CallbackManagerForLLMRun, Callbacks } from "../callbacks/manager.js";
4
- import { RunnableConfig } from "../schema/runnable.js";
4
+ import { RunnableConfig } from "../schema/runnable/config.js";
5
5
  export type SerializedLLM = {
6
6
  _model: string;
7
7
  _type: string;
@@ -330,7 +330,7 @@ class OpenAIChat extends base_js_1.LLM {
330
330
  };
331
331
  const stream = await this.completionWithRetry(params, options);
332
332
  for await (const data of stream) {
333
- const choice = data.choices[0];
333
+ const choice = data?.choices[0];
334
334
  if (!choice) {
335
335
  continue;
336
336
  }
@@ -327,7 +327,7 @@ export class OpenAIChat extends LLM {
327
327
  };
328
328
  const stream = await this.completionWithRetry(params, options);
329
329
  for await (const data of stream) {
330
- const choice = data.choices[0];
330
+ const choice = data?.choices[0];
331
331
  if (!choice) {
332
332
  continue;
333
333
  }
@@ -436,7 +436,7 @@ class OpenAI extends base_js_1.BaseLLM {
436
436
  };
437
437
  const stream = await this.completionWithRetry(params, options);
438
438
  for await (const data of stream) {
439
- const choice = data.choices[0];
439
+ const choice = data?.choices[0];
440
440
  if (!choice) {
441
441
  continue;
442
442
  }
@@ -433,7 +433,7 @@ export class OpenAI extends BaseLLM {
433
433
  };
434
434
  const stream = await this.completionWithRetry(params, options);
435
435
  for await (const data of stream) {
436
- const choice = data.choices[0];
436
+ const choice = data?.choices[0];
437
437
  if (!choice) {
438
438
  continue;
439
439
  }
@@ -55,6 +55,7 @@ exports.optionalImportEntrypoints = [
55
55
  "langchain/vectorstores/singlestore",
56
56
  "langchain/vectorstores/tigris",
57
57
  "langchain/vectorstores/usearch",
58
+ "langchain/vectorstores/voy",
58
59
  "langchain/vectorstores/zep",
59
60
  "langchain/memory/zep",
60
61
  "langchain/document_loaders/web/apify_dataset",
@@ -125,4 +126,5 @@ exports.optionalImportEntrypoints = [
125
126
  "langchain/hub",
126
127
  "langchain/experimental/multimodal_embeddings/googlevertexai",
127
128
  "langchain/experimental/chat_models/anthropic_functions",
129
+ "langchain/experimental/llms/bittensor",
128
130
  ];
@@ -52,6 +52,7 @@ export const optionalImportEntrypoints = [
52
52
  "langchain/vectorstores/singlestore",
53
53
  "langchain/vectorstores/tigris",
54
54
  "langchain/vectorstores/usearch",
55
+ "langchain/vectorstores/voy",
55
56
  "langchain/vectorstores/zep",
56
57
  "langchain/memory/zep",
57
58
  "langchain/document_loaders/web/apify_dataset",
@@ -122,4 +123,5 @@ export const optionalImportEntrypoints = [
122
123
  "langchain/hub",
123
124
  "langchain/experimental/multimodal_embeddings/googlevertexai",
124
125
  "langchain/experimental/chat_models/anthropic_functions",
126
+ "langchain/experimental/llms/bittensor",
125
127
  ];
@@ -68,7 +68,7 @@ exports.schema__document = __importStar(require("../schema/document.cjs"));
68
68
  exports.schema__output_parser = __importStar(require("../schema/output_parser.cjs"));
69
69
  exports.schema__query_constructor = __importStar(require("../schema/query_constructor.cjs"));
70
70
  exports.schema__retriever = __importStar(require("../schema/retriever.cjs"));
71
- exports.schema__runnable = __importStar(require("../schema/runnable.cjs"));
71
+ exports.schema__runnable = __importStar(require("../schema/runnable/index.cjs"));
72
72
  exports.schema__storage = __importStar(require("../schema/storage.cjs"));
73
73
  exports.callbacks = __importStar(require("../callbacks/index.cjs"));
74
74
  exports.output_parsers = __importStar(require("../output_parsers/index.cjs"));
@@ -40,7 +40,7 @@ export * as schema__document from "../schema/document.js";
40
40
  export * as schema__output_parser from "../schema/output_parser.js";
41
41
  export * as schema__query_constructor from "../schema/query_constructor.js";
42
42
  export * as schema__retriever from "../schema/retriever.js";
43
- export * as schema__runnable from "../schema/runnable.js";
43
+ export * as schema__runnable from "../schema/runnable/index.js";
44
44
  export * as schema__storage from "../schema/storage.js";
45
45
  export * as callbacks from "../callbacks/index.js";
46
46
  export * as output_parsers from "../output_parsers/index.js";
@@ -41,7 +41,7 @@ export * as schema__document from "../schema/document.js";
41
41
  export * as schema__output_parser from "../schema/output_parser.js";
42
42
  export * as schema__query_constructor from "../schema/query_constructor.js";
43
43
  export * as schema__retriever from "../schema/retriever.js";
44
- export * as schema__runnable from "../schema/runnable.js";
44
+ export * as schema__runnable from "../schema/runnable/index.js";
45
45
  export * as schema__storage from "../schema/storage.js";
46
46
  export * as callbacks from "../callbacks/index.js";
47
47
  export * as output_parsers from "../output_parsers/index.js";
@@ -138,7 +138,8 @@ async function reviver(value) {
138
138
  module[name] ??
139
139
  // look for an export with a lc_name property matching the class name
140
140
  // this is necessary for classes that are minified
141
- Object.values(module).find((v) => typeof v === "function" && (0, serializable_js_1.get_lc_unique_name)(v) === name);
141
+ Object.values(module).find((v) => typeof v === "function" &&
142
+ (0, serializable_js_1.get_lc_unique_name)(v) === name);
142
143
  if (typeof builder !== "function") {
143
144
  throw new Error(`Invalid identifer: ${pathStr} -> ${str}`);
144
145
  }
@@ -112,7 +112,8 @@ async function reviver(value) {
112
112
  module[name] ??
113
113
  // look for an export with a lc_name property matching the class name
114
114
  // this is necessary for classes that are minified
115
- Object.values(module).find((v) => typeof v === "function" && get_lc_unique_name(v) === name);
115
+ Object.values(module).find((v) => typeof v === "function" &&
116
+ get_lc_unique_name(v) === name);
116
117
  if (typeof builder !== "function") {
117
118
  throw new Error(`Invalid identifer: ${pathStr} -> ${str}`);
118
119
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.BaseExampleSelector = exports.BaseStringPromptTemplate = exports.BasePromptTemplate = exports.StringPromptValue = void 0;
6
6
  const index_js_1 = require("../schema/index.cjs");
7
7
  const serializable_js_1 = require("../load/serializable.cjs");
8
- const runnable_js_1 = require("../schema/runnable.cjs");
8
+ const index_js_2 = require("../schema/runnable/index.cjs");
9
9
  /**
10
10
  * Represents a prompt value as a string. It extends the BasePromptValue
11
11
  * class and overrides the toString and toChatMessages methods.
@@ -39,7 +39,7 @@ exports.StringPromptValue = StringPromptValue;
39
39
  * Base class for prompt templates. Exposes a format method that returns a
40
40
  * string prompt given a set of input values.
41
41
  */
42
- class BasePromptTemplate extends runnable_js_1.Runnable {
42
+ class BasePromptTemplate extends index_js_2.Runnable {
43
43
  get lc_attributes() {
44
44
  return {
45
45
  partialVariables: undefined, // python doesn't support this yet
@@ -3,7 +3,7 @@ import { BaseOutputParser } from "../schema/output_parser.js";
3
3
  import { Serializable } from "../load/serializable.js";
4
4
  import { SerializedBasePromptTemplate } from "./serde.js";
5
5
  import { SerializedFields } from "../load/map_keys.js";
6
- import { Runnable } from "../schema/runnable.js";
6
+ import { Runnable } from "../schema/runnable/index.js";
7
7
  import { BaseCallbackConfig } from "../callbacks/manager.js";
8
8
  export type TypedPromptInputValues<RunInput> = InputValues<Extract<keyof RunInput, string> | (string & Record<never, never>)>;
9
9
  /**
@@ -2,7 +2,7 @@
2
2
  // Replace with "string" when we are comfortable with a breaking change.
3
3
  import { BasePromptValue, HumanMessage, } from "../schema/index.js";
4
4
  import { Serializable } from "../load/serializable.js";
5
- import { Runnable } from "../schema/runnable.js";
5
+ import { Runnable } from "../schema/runnable/index.js";
6
6
  /**
7
7
  * Represents a prompt value as a string. It extends the BasePromptValue
8
8
  * class and overrides the toString and toChatMessages methods.
@@ -4,7 +4,7 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.ChatPromptTemplate = exports.SystemMessagePromptTemplate = exports.AIMessagePromptTemplate = exports.HumanMessagePromptTemplate = exports.ChatMessagePromptTemplate = exports.BaseChatPromptTemplate = exports.BaseMessageStringPromptTemplate = exports.MessagesPlaceholder = exports.ChatPromptValue = exports.BaseMessagePromptTemplate = void 0;
6
6
  const index_js_1 = require("../schema/index.cjs");
7
- const runnable_js_1 = require("../schema/runnable.cjs");
7
+ const index_js_2 = require("../schema/runnable/index.cjs");
8
8
  const base_js_1 = require("./base.cjs");
9
9
  const prompt_js_1 = require("./prompt.cjs");
10
10
  /**
@@ -12,7 +12,7 @@ const prompt_js_1 = require("./prompt.cjs");
12
12
  * templates. It defines how to format messages for different roles in a
13
13
  * conversation.
14
14
  */
15
- class BaseMessagePromptTemplate extends runnable_js_1.Runnable {
15
+ class BaseMessagePromptTemplate extends index_js_2.Runnable {
16
16
  constructor() {
17
17
  super(...arguments);
18
18
  Object.defineProperty(this, "lc_namespace", {
@@ -1,6 +1,6 @@
1
1
  import { BaseCallbackConfig } from "../callbacks/manager.js";
2
2
  import { BaseMessage, BaseMessageLike, BasePromptValue, InputValues, PartialValues } from "../schema/index.js";
3
- import { Runnable } from "../schema/runnable.js";
3
+ import { Runnable } from "../schema/runnable/index.js";
4
4
  import { BasePromptTemplate, BasePromptTemplateInput, BaseStringPromptTemplate, TypedPromptInputValues } from "./base.js";
5
5
  /**
6
6
  * Abstract class that serves as a base for creating message prompt
@@ -1,7 +1,7 @@
1
1
  // Default generic "any" values are for backwards compatibility.
2
2
  // Replace with "string" when we are comfortable with a breaking change.
3
3
  import { AIMessage, BaseMessage, BasePromptValue, ChatMessage, HumanMessage, SystemMessage, coerceMessageLikeToMessage, isBaseMessage, } from "../schema/index.js";
4
- import { Runnable } from "../schema/runnable.js";
4
+ import { Runnable } from "../schema/runnable/index.js";
5
5
  import { BasePromptTemplate, } from "./base.js";
6
6
  import { PromptTemplate } from "./prompt.js";
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MappingDocumentTransformer = exports.BaseDocumentTransformer = void 0;
4
- const runnable_js_1 = require("./runnable.cjs");
4
+ const index_js_1 = require("./runnable/index.cjs");
5
5
  /**
6
6
  * Abstract base class for document transformation systems.
7
7
  *
@@ -12,7 +12,7 @@ const runnable_js_1 = require("./runnable.cjs");
12
12
  * One example of this is a text splitter that splits a large document into
13
13
  * many smaller documents.
14
14
  */
15
- class BaseDocumentTransformer extends runnable_js_1.Runnable {
15
+ class BaseDocumentTransformer extends index_js_1.Runnable {
16
16
  constructor() {
17
17
  super(...arguments);
18
18
  Object.defineProperty(this, "lc_namespace", {
@@ -1,6 +1,6 @@
1
1
  import { BaseCallbackConfig } from "../callbacks/manager.js";
2
2
  import { Document } from "../document.js";
3
- import { Runnable } from "./runnable.js";
3
+ import { Runnable } from "./runnable/index.js";
4
4
  /**
5
5
  * Abstract base class for document transformation systems.
6
6
  *
@@ -1,4 +1,4 @@
1
- import { Runnable } from "./runnable.js";
1
+ import { Runnable } from "./runnable/index.js";
2
2
  /**
3
3
  * Abstract base class for document transformation systems.
4
4
  *
@@ -333,35 +333,18 @@ function coerceMessageLikeToMessage(messageLike) {
333
333
  else if (isBaseMessage(messageLike)) {
334
334
  return messageLike;
335
335
  }
336
- let role;
337
- let content;
338
- let name;
339
- if (Array.isArray(messageLike)) {
340
- [role, content] = messageLike;
341
- name = "";
342
- }
343
- else {
344
- role = messageLike.role;
345
- content = messageLike.content;
346
- name = messageLike.name;
347
- }
348
- if (role === "human" || role === "user") {
336
+ const [type, content] = messageLike;
337
+ if (type === "human" || type === "user") {
349
338
  return new HumanMessage({ content });
350
339
  }
351
- else if (role === "ai" || role === "assistant") {
340
+ else if (type === "ai" || type === "assistant") {
352
341
  return new AIMessage({ content });
353
342
  }
354
- else if (role === "system") {
343
+ else if (type === "system") {
355
344
  return new SystemMessage({ content });
356
345
  }
357
- else if (role === "function") {
358
- if (!name) {
359
- throw new Error(`Unable to coerce function message from object: no "name" field provided.`);
360
- }
361
- return new FunctionMessage({ content, name });
362
- }
363
346
  else {
364
- return new ChatMessage({ content, role });
347
+ throw new Error(`Unable to coerce message from array: only human, AI, or system message coercion is currently supported.`);
365
348
  }
366
349
  }
367
350
  exports.coerceMessageLikeToMessage = coerceMessageLikeToMessage;
@@ -210,11 +210,7 @@ export declare class ChatMessage extends BaseMessage implements ChatMessageField
210
210
  _getType(): MessageType;
211
211
  static isInstance(message: BaseMessage): message is ChatMessage;
212
212
  }
213
- export type BaseMessageLike = BaseMessage | {
214
- role: MessageType | "user" | "assistant" | (string & Record<never, never>);
215
- content: string;
216
- name?: string;
217
- } | [
213
+ export type BaseMessageLike = BaseMessage | [
218
214
  MessageType | "user" | "assistant" | (string & Record<never, never>),
219
215
  string
220
216
  ] | string;
@@ -317,35 +317,18 @@ export function coerceMessageLikeToMessage(messageLike) {
317
317
  else if (isBaseMessage(messageLike)) {
318
318
  return messageLike;
319
319
  }
320
- let role;
321
- let content;
322
- let name;
323
- if (Array.isArray(messageLike)) {
324
- [role, content] = messageLike;
325
- name = "";
326
- }
327
- else {
328
- role = messageLike.role;
329
- content = messageLike.content;
330
- name = messageLike.name;
331
- }
332
- if (role === "human" || role === "user") {
320
+ const [type, content] = messageLike;
321
+ if (type === "human" || type === "user") {
333
322
  return new HumanMessage({ content });
334
323
  }
335
- else if (role === "ai" || role === "assistant") {
324
+ else if (type === "ai" || type === "assistant") {
336
325
  return new AIMessage({ content });
337
326
  }
338
- else if (role === "system") {
327
+ else if (type === "system") {
339
328
  return new SystemMessage({ content });
340
329
  }
341
- else if (role === "function") {
342
- if (!name) {
343
- throw new Error(`Unable to coerce function message from object: no "name" field provided.`);
344
- }
345
- return new FunctionMessage({ content, name });
346
- }
347
330
  else {
348
- return new ChatMessage({ content, role });
331
+ throw new Error(`Unable to coerce message from array: only human, AI, or system message coercion is currently supported.`);
349
332
  }
350
333
  }
351
334
  /**
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OutputParserException = exports.BytesOutputParser = exports.StringOutputParser = exports.BaseTransformOutputParser = exports.BaseOutputParser = exports.BaseLLMOutputParser = void 0;
4
- const runnable_js_1 = require("./runnable.cjs");
4
+ const index_js_1 = require("./runnable/index.cjs");
5
5
  /**
6
6
  * Abstract base class for parsing the output of a Large Language Model
7
7
  * (LLM) call. It provides methods for parsing the result of an LLM call
8
8
  * and invoking the parser with a given input.
9
9
  */
10
- class BaseLLMOutputParser extends runnable_js_1.Runnable {
10
+ class BaseLLMOutputParser extends index_js_1.Runnable {
11
11
  /**
12
12
  * Parses the result of an LLM call with a given prompt. By default, it
13
13
  * simply calls `parseResult`.
@@ -1,6 +1,7 @@
1
1
  import { BaseCallbackConfig, Callbacks } from "../callbacks/manager.js";
2
2
  import { BasePromptValue, Generation, ChatGeneration, BaseMessage } from "./index.js";
3
- import { Runnable, RunnableConfig } from "./runnable.js";
3
+ import { Runnable } from "./runnable/index.js";
4
+ import { RunnableConfig } from "./runnable/config.js";
4
5
  /**
5
6
  * Options for formatting instructions.
6
7
  */
@@ -1,4 +1,4 @@
1
- import { Runnable } from "./runnable.js";
1
+ import { Runnable } from "./runnable/index.js";
2
2
  /**
3
3
  * Abstract base class for parsing the output of a Large Language Model
4
4
  * (LLM) call. It provides methods for parsing the result of an LLM call
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseRetriever = void 0;
4
4
  const manager_js_1 = require("../callbacks/manager.cjs");
5
- const runnable_js_1 = require("./runnable.cjs");
5
+ const index_js_1 = require("./runnable/index.cjs");
6
6
  /**
7
7
  * Abstract base class for a Document retrieval system. A retrieval system
8
8
  * is defined as something that can take string queries and return the
9
9
  * most 'relevant' Documents from some source.
10
10
  */
11
- class BaseRetriever extends runnable_js_1.Runnable {
11
+ class BaseRetriever extends index_js_1.Runnable {
12
12
  constructor(fields) {
13
13
  super(fields);
14
14
  Object.defineProperty(this, "callbacks", {
@@ -1,6 +1,7 @@
1
1
  import { BaseCallbackConfig, CallbackManagerForRetrieverRun, Callbacks } from "../callbacks/manager.js";
2
2
  import { Document } from "../document.js";
3
- import { Runnable, RunnableConfig } from "./runnable.js";
3
+ import { Runnable } from "./runnable/index.js";
4
+ import { RunnableConfig } from "./runnable/config.js";
4
5
  /**
5
6
  * Base Retriever class. All indexes should extend this class.
6
7
  */
@@ -1,5 +1,5 @@
1
1
  import { CallbackManager, parseCallbackConfigArg, } from "../callbacks/manager.js";
2
- import { Runnable } from "./runnable.js";
2
+ import { Runnable } from "./runnable/index.js";
3
3
  /**
4
4
  * Abstract base class for a Document retrieval system. A retrieval system
5
5
  * is defined as something that can take string queries and return the
@@ -0,0 +1,8 @@
1
+ "use strict";
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;
@@ -0,0 +1,3 @@
1
+ import { BaseCallbackConfig, CallbackManager } from "../../callbacks/manager.js";
2
+ export type RunnableConfig = BaseCallbackConfig;
3
+ export declare function getCallbackMangerForConfig(config?: RunnableConfig): Promise<CallbackManager | undefined>;
@@ -0,0 +1,4 @@
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
+ }