langchain 0.3.28 → 0.3.30

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 (193) hide show
  1. package/README.md +15 -12
  2. package/dist/agents/agent.cjs +37 -4
  3. package/dist/agents/agent.d.ts +1 -1
  4. package/dist/agents/agent.js +1 -1
  5. package/dist/agents/format_scratchpad/log.cjs +1 -2
  6. package/dist/agents/format_scratchpad/log_to_message.cjs +1 -2
  7. package/dist/agents/format_scratchpad/openai_functions.cjs +2 -3
  8. package/dist/agents/format_scratchpad/tool_calling.cjs +2 -3
  9. package/dist/agents/format_scratchpad/xml.cjs +1 -2
  10. package/dist/agents/initialize.cjs +2 -2
  11. package/dist/agents/mrkl/index.cjs +1 -1
  12. package/dist/agents/mrkl/index.d.ts +1 -1
  13. package/dist/agents/mrkl/index.js +1 -1
  14. package/dist/agents/openai_functions/index.cjs +4 -3
  15. package/dist/agents/openai_functions/index.d.ts +1 -0
  16. package/dist/agents/openai_functions/index.js +1 -0
  17. package/dist/agents/openai_functions/output_parser.cjs +1 -1
  18. package/dist/agents/openai_functions/output_parser.d.ts +1 -1
  19. package/dist/agents/openai_functions/output_parser.js +1 -1
  20. package/dist/agents/openai_tools/index.cjs +3 -3
  21. package/dist/agents/openai_tools/index.d.ts +1 -1
  22. package/dist/agents/openai_tools/index.js +1 -1
  23. package/dist/agents/openai_tools/output_parser.cjs +1 -1
  24. package/dist/agents/openai_tools/output_parser.d.ts +1 -1
  25. package/dist/agents/openai_tools/output_parser.js +1 -1
  26. package/dist/agents/react/index.cjs +1 -2
  27. package/dist/agents/structured_chat/index.cjs +3 -3
  28. package/dist/agents/structured_chat/index.d.ts +1 -1
  29. package/dist/agents/structured_chat/index.js +1 -1
  30. package/dist/agents/structured_chat/outputParser.cjs +1 -1
  31. package/dist/agents/structured_chat/outputParser.d.ts +1 -1
  32. package/dist/agents/structured_chat/outputParser.js +1 -1
  33. package/dist/agents/structured_chat/prompt.d.ts +1 -1
  34. package/dist/agents/tool_calling/index.cjs +1 -2
  35. package/dist/agents/tool_calling/output_parser.cjs +2 -2
  36. package/dist/agents/toolkits/conversational_retrieval/openai_functions.cjs +1 -2
  37. package/dist/agents/toolkits/conversational_retrieval/tool.cjs +1 -2
  38. package/dist/agents/toolkits/json/json.cjs +2 -2
  39. package/dist/agents/toolkits/openapi/openapi.cjs +3 -3
  40. package/dist/agents/toolkits/openapi/openapi.d.ts +1 -1
  41. package/dist/agents/toolkits/openapi/openapi.js +1 -1
  42. package/dist/agents/toolkits/sql/sql.cjs +3 -3
  43. package/dist/agents/toolkits/sql/sql.d.ts +1 -1
  44. package/dist/agents/toolkits/sql/sql.js +1 -1
  45. package/dist/agents/toolkits/vectorstore/vectorstore.cjs +4 -4
  46. package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +1 -1
  47. package/dist/agents/toolkits/vectorstore/vectorstore.js +1 -1
  48. package/dist/agents/xml/index.cjs +2 -2
  49. package/dist/chains/analyze_documents_chain.cjs +1 -1
  50. package/dist/chains/analyze_documents_chain.d.ts +1 -1
  51. package/dist/chains/analyze_documents_chain.js +1 -1
  52. package/dist/chains/api/prompts.d.ts +1 -1
  53. package/dist/chains/base.cjs +42 -9
  54. package/dist/chains/base.d.ts +2 -2
  55. package/dist/chains/base.js +1 -1
  56. package/dist/chains/combine_documents/base.cjs +2 -2
  57. package/dist/chains/combine_documents/reduce.cjs +2 -3
  58. package/dist/chains/combine_documents/stuff.cjs +1 -2
  59. package/dist/chains/constitutional_ai/constitutional_principle.cjs +2 -2
  60. package/dist/chains/constitutional_ai/constitutional_principle.d.ts +2 -2
  61. package/dist/chains/constitutional_ai/constitutional_principle.js +2 -2
  62. package/dist/chains/conversation.cjs +1 -1
  63. package/dist/chains/conversation.d.ts +1 -1
  64. package/dist/chains/conversation.js +1 -1
  65. package/dist/chains/graph_qa/cypher.cjs +1 -1
  66. package/dist/chains/graph_qa/cypher.d.ts +1 -1
  67. package/dist/chains/graph_qa/cypher.js +1 -1
  68. package/dist/chains/history_aware_retriever.cjs +2 -3
  69. package/dist/chains/history_aware_retriever.d.ts +1 -1
  70. package/dist/chains/history_aware_retriever.js +1 -1
  71. package/dist/chains/llm_chain.cjs +1 -1
  72. package/dist/chains/llm_chain.d.ts +1 -1
  73. package/dist/chains/llm_chain.js +1 -1
  74. package/dist/chains/openai_functions/base.cjs +3 -4
  75. package/dist/chains/openai_functions/base.d.ts +1 -1
  76. package/dist/chains/openai_functions/base.js +1 -1
  77. package/dist/chains/openai_functions/extraction.cjs +2 -3
  78. package/dist/chains/openai_functions/openapi.cjs +4 -5
  79. package/dist/chains/openai_functions/openapi.js +1 -1
  80. package/dist/chains/openai_functions/structured_output.cjs +4 -4
  81. package/dist/chains/openai_functions/structured_output.js +1 -1
  82. package/dist/chains/openai_functions/tagging.cjs +2 -3
  83. package/dist/chains/query_constructor/index.cjs +3 -3
  84. package/dist/chains/question_answering/load.cjs +4 -4
  85. package/dist/chains/retrieval.cjs +2 -3
  86. package/dist/chains/retrieval.d.ts +1 -1
  87. package/dist/chains/retrieval.js +1 -1
  88. package/dist/chains/router/multi_prompt.cjs +16 -13
  89. package/dist/chains/router/multi_prompt.d.ts +16 -13
  90. package/dist/chains/router/multi_prompt.js +16 -13
  91. package/dist/chains/router/multi_retrieval_qa.cjs +1 -1
  92. package/dist/chains/router/multi_retrieval_qa.d.ts +1 -1
  93. package/dist/chains/router/multi_retrieval_qa.js +1 -1
  94. package/dist/chains/router/utils.cjs +1 -2
  95. package/dist/chains/sequential_chain.cjs +4 -3
  96. package/dist/chains/sequential_chain.d.ts +2 -2
  97. package/dist/chains/sequential_chain.js +4 -3
  98. package/dist/chains/sql_db/sql_db_chain.cjs +3 -3
  99. package/dist/chains/sql_db/sql_db_chain.d.ts +1 -1
  100. package/dist/chains/sql_db/sql_db_chain.js +1 -1
  101. package/dist/chat_models/universal.cjs +54 -21
  102. package/dist/document_loaders/fs/buffer.cjs +34 -1
  103. package/dist/document_loaders/fs/buffer.d.ts +0 -3
  104. package/dist/document_loaders/fs/directory.cjs +35 -2
  105. package/dist/document_loaders/fs/directory.d.ts +0 -2
  106. package/dist/document_loaders/fs/text.cjs +34 -1
  107. package/dist/document_loaders/fs/text.d.ts +0 -1
  108. package/dist/document_transformers/openai_functions.cjs +4 -4
  109. package/dist/document_transformers/openai_functions.js +1 -1
  110. package/dist/evaluation/embedding_distance/base.cjs +3 -3
  111. package/dist/evaluation/loader.cjs +2 -3
  112. package/dist/evaluation/loader.js +1 -1
  113. package/dist/experimental/autogpt/agent.cjs +1 -1
  114. package/dist/experimental/autogpt/agent.d.ts +1 -1
  115. package/dist/experimental/autogpt/agent.js +1 -1
  116. package/dist/experimental/autogpt/output_parser.cjs +2 -2
  117. package/dist/experimental/autogpt/prompt_generator.cjs +2 -2
  118. package/dist/experimental/generative_agents/generative_agent.cjs +2 -2
  119. package/dist/experimental/generative_agents/generative_agent.d.ts +1 -1
  120. package/dist/experimental/generative_agents/generative_agent.js +2 -2
  121. package/dist/experimental/openai_assistant/index.cjs +8 -4
  122. package/dist/experimental/openai_assistant/index.d.ts +6 -6
  123. package/dist/experimental/openai_assistant/index.js +9 -5
  124. package/dist/experimental/openai_files/index.cjs +2 -2
  125. package/dist/experimental/openai_files/index.d.ts +6 -4
  126. package/dist/experimental/openai_files/index.js +2 -2
  127. package/dist/experimental/plan_and_execute/agent_executor.cjs +2 -2
  128. package/dist/hub/base.cjs +4 -5
  129. package/dist/hub/index.cjs +2 -2
  130. package/dist/hub/node.cjs +43 -10
  131. package/dist/index.cjs +0 -1
  132. package/dist/index.d.ts +0 -1
  133. package/dist/index.js +1 -1
  134. package/dist/load/import_map.cjs +17 -7
  135. package/dist/load/index.cjs +18 -9
  136. package/dist/memory/buffer_memory.cjs +1 -1
  137. package/dist/memory/buffer_memory.d.ts +1 -1
  138. package/dist/memory/buffer_memory.js +1 -1
  139. package/dist/memory/buffer_token_memory.cjs +1 -1
  140. package/dist/memory/buffer_token_memory.d.ts +1 -1
  141. package/dist/memory/buffer_token_memory.js +1 -1
  142. package/dist/memory/buffer_window_memory.cjs +1 -1
  143. package/dist/memory/buffer_window_memory.d.ts +1 -1
  144. package/dist/memory/buffer_window_memory.js +1 -1
  145. package/dist/memory/entity_memory.cjs +2 -2
  146. package/dist/memory/entity_memory.d.ts +2 -2
  147. package/dist/memory/entity_memory.js +2 -2
  148. package/dist/memory/summary.cjs +2 -2
  149. package/dist/memory/summary.d.ts +2 -2
  150. package/dist/memory/summary.js +2 -2
  151. package/dist/memory/summary_buffer.cjs +2 -2
  152. package/dist/memory/summary_buffer.d.ts +2 -2
  153. package/dist/memory/summary_buffer.js +2 -2
  154. package/dist/output_parsers/expression_type_handlers/base.cjs +34 -1
  155. package/dist/prompts/index.cjs +0 -1
  156. package/dist/prompts/index.d.ts +0 -1
  157. package/dist/prompts/index.js +1 -1
  158. package/dist/retrievers/hyde.cjs +3 -3
  159. package/dist/retrievers/hyde.d.ts +1 -1
  160. package/dist/retrievers/hyde.js +1 -1
  161. package/dist/retrievers/parent_document.cjs +17 -7
  162. package/dist/retrievers/self_query/index.cjs +1 -1
  163. package/dist/retrievers/self_query/index.d.ts +1 -1
  164. package/dist/retrievers/self_query/index.js +1 -1
  165. package/dist/smith/config.cjs +5 -6
  166. package/dist/smith/name_generation.cjs +1 -2
  167. package/dist/smith/runner_utils.cjs +1 -2
  168. package/dist/sql_db.cjs +35 -2
  169. package/dist/storage/encoder_backed.cjs +2 -2
  170. package/dist/storage/encoder_backed.d.ts +1 -1
  171. package/dist/storage/file_system.cjs +17 -7
  172. package/dist/storage/file_system.d.ts +1 -1
  173. package/dist/stores/file/node.cjs +17 -7
  174. package/dist/tools/convert_to_openai.cjs +2 -2
  175. package/dist/tools/render.cjs +2 -3
  176. package/dist/tools/retriever.cjs +1 -2
  177. package/dist/tools/webbrowser.cjs +18 -8
  178. package/dist/tools/webbrowser.d.ts +1 -1
  179. package/dist/tools/webbrowser.js +1 -1
  180. package/dist/util/axios-fetch-adapter.cjs +1 -1
  181. package/dist/util/azure.cjs +1 -2
  182. package/dist/util/entrypoint_deprecation.cjs +2 -3
  183. package/dist/util/load.cjs +34 -1
  184. package/dist/util/ml-distance/distances.cjs +3 -4
  185. package/dist/util/ml-distance/similarities.cjs +1 -2
  186. package/dist/util/ml-distance-euclidean/euclidean.cjs +2 -3
  187. package/dist/util/openapi.cjs +17 -7
  188. package/dist/util/openapi.d.ts +32 -32
  189. package/dist/util/parse.cjs +17 -7
  190. package/dist/util/prompt-layer.d.ts +1 -1
  191. package/dist/util/set.cjs +3 -4
  192. package/dist/util/time.cjs +1 -2
  193. package/package.json +9 -9
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createOpenApiAgent = exports.OpenApiToolkit = exports.RequestsToolkit = void 0;
3
+ exports.OpenApiToolkit = exports.RequestsToolkit = void 0;
4
+ exports.createOpenApiAgent = createOpenApiAgent;
4
5
  const tools_1 = require("@langchain/core/tools");
5
6
  const executor_js_1 = require("../../executor.cjs");
6
7
  const prompt_js_1 = require("./prompt.cjs");
@@ -35,7 +36,7 @@ exports.RequestsToolkit = RequestsToolkit;
35
36
  * const toolkit = new OpenApiToolkit(
36
37
  * new JsonSpec({
37
38
  * }),
38
- * new ChatOpenAI({ temperature: 0 }),
39
+ * new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
39
40
  * {
40
41
  * "Content-Type": "application/json",
41
42
  * Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
@@ -108,4 +109,3 @@ function createOpenApiAgent(llm, openApiToolkit, args) {
108
109
  returnIntermediateSteps: true,
109
110
  });
110
111
  }
111
- exports.createOpenApiAgent = createOpenApiAgent;
@@ -23,7 +23,7 @@ export declare class RequestsToolkit extends BaseToolkit {
23
23
  * const toolkit = new OpenApiToolkit(
24
24
  * new JsonSpec({
25
25
  * }),
26
- * new ChatOpenAI({ temperature: 0 }),
26
+ * new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
27
27
  * {
28
28
  * "Content-Type": "application/json",
29
29
  * Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
@@ -31,7 +31,7 @@ export class RequestsToolkit extends BaseToolkit {
31
31
  * const toolkit = new OpenApiToolkit(
32
32
  * new JsonSpec({
33
33
  * }),
34
- * new ChatOpenAI({ temperature: 0 }),
34
+ * new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
35
35
  * {
36
36
  * "Content-Type": "application/json",
37
37
  * Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSqlAgent = exports.SqlToolkit = void 0;
3
+ exports.SqlToolkit = void 0;
4
+ exports.createSqlAgent = createSqlAgent;
4
5
  const tools_1 = require("@langchain/core/tools");
5
6
  const prompts_1 = require("@langchain/core/prompts");
6
7
  const sql_js_1 = require("../../../tools/sql.cjs");
@@ -13,7 +14,7 @@ const executor_js_1 = require("../../executor.cjs");
13
14
  * initializes SQL tools based on the provided SQL database.
14
15
  * @example
15
16
  * ```typescript
16
- * const model = new ChatOpenAI({});
17
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
17
18
  * const toolkit = new SqlToolkit(sqlDb, model);
18
19
  * const executor = createSqlAgent(model, toolkit);
19
20
  * const result = await executor.invoke({ input: 'List the total sales per country. Which country's customers spent the most?' });
@@ -74,4 +75,3 @@ function createSqlAgent(llm, toolkit, args) {
74
75
  returnIntermediateSteps: true,
75
76
  });
76
77
  }
77
- exports.createSqlAgent = createSqlAgent;
@@ -16,7 +16,7 @@ export interface SqlCreatePromptArgs extends ZeroShotCreatePromptArgs {
16
16
  * initializes SQL tools based on the provided SQL database.
17
17
  * @example
18
18
  * ```typescript
19
- * const model = new ChatOpenAI({});
19
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
20
20
  * const toolkit = new SqlToolkit(sqlDb, model);
21
21
  * const executor = createSqlAgent(model, toolkit);
22
22
  * const result = await executor.invoke({ input: 'List the total sales per country. Which country's customers spent the most?' });
@@ -10,7 +10,7 @@ import { AgentExecutor } from "../../executor.js";
10
10
  * initializes SQL tools based on the provided SQL database.
11
11
  * @example
12
12
  * ```typescript
13
- * const model = new ChatOpenAI({});
13
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
14
14
  * const toolkit = new SqlToolkit(sqlDb, model);
15
15
  * const executor = createSqlAgent(model, toolkit);
16
16
  * const result = await executor.invoke({ input: 'List the total sales per country. Which country's customers spent the most?' });
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createVectorStoreRouterAgent = exports.createVectorStoreAgent = exports.VectorStoreRouterToolkit = exports.VectorStoreToolkit = void 0;
3
+ exports.VectorStoreRouterToolkit = exports.VectorStoreToolkit = void 0;
4
+ exports.createVectorStoreAgent = createVectorStoreAgent;
5
+ exports.createVectorStoreRouterAgent = createVectorStoreRouterAgent;
4
6
  const tools_1 = require("@langchain/core/tools");
5
7
  const vectorstore_js_1 = require("../../../tools/vectorstore.cjs");
6
8
  const index_js_1 = require("../../mrkl/index.cjs");
@@ -20,7 +22,7 @@ const executor_js_1 = require("../../executor.cjs");
20
22
  * description: "the most recent state of the Union address",
21
23
  * vectorStore: new HNSWLib(),
22
24
  * },
23
- * new ChatOpenAI({ temperature: 0 }),
25
+ * new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
24
26
  * );
25
27
  * const result = await toolkit.invoke({
26
28
  * input:
@@ -113,7 +115,6 @@ function createVectorStoreAgent(llm, toolkit, args) {
113
115
  returnIntermediateSteps: true,
114
116
  });
115
117
  }
116
- exports.createVectorStoreAgent = createVectorStoreAgent;
117
118
  /** @deprecated Create a specific agent with a custom tool instead. */
118
119
  function createVectorStoreRouterAgent(llm, toolkit, args) {
119
120
  const { prefix = prompt_js_1.VECTOR_ROUTER_PREFIX, suffix = prompt_js_2.SUFFIX, inputVariables = ["input", "agent_scratchpad"], } = args ?? {};
@@ -134,4 +135,3 @@ function createVectorStoreRouterAgent(llm, toolkit, args) {
134
135
  returnIntermediateSteps: true,
135
136
  });
136
137
  }
137
- exports.createVectorStoreRouterAgent = createVectorStoreRouterAgent;
@@ -24,7 +24,7 @@ export interface VectorStoreInfo {
24
24
  * description: "the most recent state of the Union address",
25
25
  * vectorStore: new HNSWLib(),
26
26
  * },
27
- * new ChatOpenAI({ temperature: 0 }),
27
+ * new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
28
28
  * );
29
29
  * const result = await toolkit.invoke({
30
30
  * input:
@@ -17,7 +17,7 @@ import { AgentExecutor } from "../../executor.js";
17
17
  * description: "the most recent state of the Union address",
18
18
  * vectorStore: new HNSWLib(),
19
19
  * },
20
- * new ChatOpenAI({ temperature: 0 }),
20
+ * new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
21
21
  * );
22
22
  * const result = await toolkit.invoke({
23
23
  * input:
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createXmlAgent = exports.XMLAgent = void 0;
3
+ exports.XMLAgent = void 0;
4
+ exports.createXmlAgent = createXmlAgent;
4
5
  const runnables_1 = require("@langchain/core/runnables");
5
6
  const prompts_1 = require("@langchain/core/prompts");
6
7
  const llm_chain_js_1 = require("../../chains/llm_chain.cjs");
@@ -182,4 +183,3 @@ async function createXmlAgent({ llm, tools, prompt, streamRunnable, }) {
182
183
  });
183
184
  return agent;
184
185
  }
185
- exports.createXmlAgent = createXmlAgent;
@@ -9,7 +9,7 @@ const text_splitter_js_1 = require("../text_splitter.cjs");
9
9
  * @augments StuffDocumentsChainInput
10
10
  * @example
11
11
  * ```typescript
12
- * const model = new ChatOpenAI({ temperature: 0 });
12
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 });
13
13
  * const combineDocsChain = loadSummarizationChain(model);
14
14
  * const chain = new AnalyzeDocumentChain({
15
15
  * combineDocumentsChain: combineDocsChain,
@@ -19,7 +19,7 @@ export interface AnalyzeDocumentChainInput extends Omit<ChainInputs, "memory"> {
19
19
  * @augments StuffDocumentsChainInput
20
20
  * @example
21
21
  * ```typescript
22
- * const model = new ChatOpenAI({ temperature: 0 });
22
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 });
23
23
  * const combineDocsChain = loadSummarizationChain(model);
24
24
  * const chain = new AnalyzeDocumentChain({
25
25
  * combineDocumentsChain: combineDocsChain,
@@ -6,7 +6,7 @@ import { RecursiveCharacterTextSplitter, } from "../text_splitter.js";
6
6
  * @augments StuffDocumentsChainInput
7
7
  * @example
8
8
  * ```typescript
9
- * const model = new ChatOpenAI({ temperature: 0 });
9
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 });
10
10
  * const combineDocsChain = loadSummarizationChain(model);
11
11
  * const chain = new AnalyzeDocumentChain({
12
12
  * combineDocumentsChain: combineDocsChain,
@@ -4,7 +4,7 @@ export declare const API_URL_PROMPT_TEMPLATE: PromptTemplate<{
4
4
  question: any;
5
5
  api_docs: any;
6
6
  }, any>;
7
- export declare const API_RESPONSE_RAW_PROMPT_TEMPLATE: string;
7
+ export declare const API_RESPONSE_RAW_PROMPT_TEMPLATE = "You are given the below API Documentation:\n{api_docs}\nUsing this documentation, generate the full API url to call for answering the user question.\nYou should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n\nQuestion:{question}\nAPI url: {api_url}\n\nHere is the response from the API:\n\n{api_response}\n\nSummarize this response to answer the original question.\n\nSummary:";
8
8
  export declare const API_RESPONSE_PROMPT_TEMPLATE: PromptTemplate<{
9
9
  question: any;
10
10
  api_docs: any;
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.BaseChain = void 0;
4
37
  const outputs_1 = require("@langchain/core/outputs");
@@ -107,7 +140,7 @@ class BaseChain extends base_1.BaseLangChain {
107
140
  async run(
108
141
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
142
  input, config) {
110
- const inputKeys = this.inputKeys.filter((k) => !this.memory?.memoryKeys.includes(k) ?? true);
143
+ const inputKeys = this.inputKeys.filter((k) => !this.memory?.memoryKeys.includes(k));
111
144
  const isKeylessInput = inputKeys.length <= 1;
112
145
  if (!isKeylessInput) {
113
146
  throw new Error(`Chain ${this._chainType()} expects multiple inputs, cannot use 'run' `);
@@ -162,35 +195,35 @@ class BaseChain extends base_1.BaseLangChain {
162
195
  static async deserialize(data, values = {}) {
163
196
  switch (data._type) {
164
197
  case "llm_chain": {
165
- const { LLMChain } = await import("./llm_chain.js");
198
+ const { LLMChain } = await Promise.resolve().then(() => __importStar(require("./llm_chain.cjs")));
166
199
  return LLMChain.deserialize(data);
167
200
  }
168
201
  case "sequential_chain": {
169
- const { SequentialChain } = await import("./sequential_chain.js");
202
+ const { SequentialChain } = await Promise.resolve().then(() => __importStar(require("./sequential_chain.cjs")));
170
203
  return SequentialChain.deserialize(data);
171
204
  }
172
205
  case "simple_sequential_chain": {
173
- const { SimpleSequentialChain } = await import("./sequential_chain.js");
206
+ const { SimpleSequentialChain } = await Promise.resolve().then(() => __importStar(require("./sequential_chain.cjs")));
174
207
  return SimpleSequentialChain.deserialize(data);
175
208
  }
176
209
  case "stuff_documents_chain": {
177
- const { StuffDocumentsChain } = await import("./combine_docs_chain.js");
210
+ const { StuffDocumentsChain } = await Promise.resolve().then(() => __importStar(require("./combine_docs_chain.cjs")));
178
211
  return StuffDocumentsChain.deserialize(data);
179
212
  }
180
213
  case "map_reduce_documents_chain": {
181
- const { MapReduceDocumentsChain } = await import("./combine_docs_chain.js");
214
+ const { MapReduceDocumentsChain } = await Promise.resolve().then(() => __importStar(require("./combine_docs_chain.cjs")));
182
215
  return MapReduceDocumentsChain.deserialize(data);
183
216
  }
184
217
  case "refine_documents_chain": {
185
- const { RefineDocumentsChain } = await import("./combine_docs_chain.js");
218
+ const { RefineDocumentsChain } = await Promise.resolve().then(() => __importStar(require("./combine_docs_chain.cjs")));
186
219
  return RefineDocumentsChain.deserialize(data);
187
220
  }
188
221
  case "vector_db_qa": {
189
- const { VectorDBQAChain } = await import("./vector_db_qa.js");
222
+ const { VectorDBQAChain } = await Promise.resolve().then(() => __importStar(require("./vector_db_qa.cjs")));
190
223
  return VectorDBQAChain.deserialize(data, values);
191
224
  }
192
225
  case "api_chain": {
193
- const { APIChain } = await import("./api/api_chain.js");
226
+ const { APIChain } = await Promise.resolve().then(() => __importStar(require("./api/api_chain.cjs")));
194
227
  return APIChain.deserialize(data);
195
228
  }
196
229
  default:
@@ -54,8 +54,8 @@ export declare abstract class BaseChain<RunInput extends ChainValues = ChainValu
54
54
  signal?: AbortSignal;
55
55
  timeout?: number;
56
56
  }): Promise<ChainValues & {
57
- signal?: AbortSignal | undefined;
58
- timeout?: number | undefined;
57
+ signal?: AbortSignal;
58
+ timeout?: number;
59
59
  }>;
60
60
  /**
61
61
  * @deprecated Use .invoke() instead. Will be removed in 0.2.0.
@@ -104,7 +104,7 @@ export class BaseChain extends BaseLangChain {
104
104
  async run(
105
105
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
106
  input, config) {
107
- const inputKeys = this.inputKeys.filter((k) => !this.memory?.memoryKeys.includes(k) ?? true);
107
+ const inputKeys = this.inputKeys.filter((k) => !this.memory?.memoryKeys.includes(k));
108
108
  const isKeylessInput = inputKeys.length <= 1;
109
109
  if (!isKeylessInput) {
110
110
  throw new Error(`Chain ${this._chainType()} expects multiple inputs, cannot use 'run' `);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatDocuments = exports.DEFAULT_DOCUMENT_PROMPT = exports.INTERMEDIATE_STEPS_KEY = exports.DOCUMENTS_KEY = exports.DEFAULT_DOCUMENT_SEPARATOR = void 0;
3
+ exports.DEFAULT_DOCUMENT_PROMPT = exports.INTERMEDIATE_STEPS_KEY = exports.DOCUMENTS_KEY = exports.DEFAULT_DOCUMENT_SEPARATOR = void 0;
4
+ exports.formatDocuments = formatDocuments;
4
5
  const prompts_1 = require("@langchain/core/prompts");
5
6
  exports.DEFAULT_DOCUMENT_SEPARATOR = "\n\n";
6
7
  exports.DOCUMENTS_KEY = "context";
@@ -16,4 +17,3 @@ async function formatDocuments({ documentPrompt, documentSeparator, documents, c
16
17
  .invoke({ ...document.metadata, page_content: document.pageContent }, config)));
17
18
  return formattedDocs.join(documentSeparator);
18
19
  }
19
- exports.formatDocuments = formatDocuments;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collapseDocs = exports.splitListOfDocs = void 0;
3
+ exports.splitListOfDocs = splitListOfDocs;
4
+ exports.collapseDocs = collapseDocs;
4
5
  /**
5
6
  * Splits a list of documents into sublists based on a maximum token limit.
6
7
  *
@@ -31,7 +32,6 @@ lengthFunc, tokenMax) {
31
32
  newResultDocList.push(subResultDocs);
32
33
  return newResultDocList;
33
34
  }
34
- exports.splitListOfDocs = splitListOfDocs;
35
35
  /**
36
36
  * Collapses a list of documents into a single document.
37
37
  *
@@ -50,7 +50,6 @@ async function collapseDocs(docs, combineDocumentFunc) {
50
50
  const result = await combineDocumentFunc(docs);
51
51
  return { pageContent: result, metadata: collapseDocsMetadata(docs) };
52
52
  }
53
- exports.collapseDocs = collapseDocs;
54
53
  function collapseDocsMetadata(docs) {
55
54
  const combinedMetadata = {};
56
55
  for (const key in docs[0].metadata) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createStuffDocumentsChain = void 0;
3
+ exports.createStuffDocumentsChain = createStuffDocumentsChain;
4
4
  const output_parsers_1 = require("@langchain/core/output_parsers");
5
5
  const runnables_1 = require("@langchain/core/runnables");
6
6
  const base_js_1 = require("./base.cjs");
@@ -39,4 +39,3 @@ async function createStuffDocumentsChain({ llm, prompt, outputParser = new outpu
39
39
  outputParser,
40
40
  ], "stuff_documents_chain");
41
41
  }
42
- exports.createStuffDocumentsChain = createStuffDocumentsChain;
@@ -12,9 +12,9 @@ exports.PRINCIPLES = exports.ConstitutionalPrinciple = void 0;
12
12
  * revisionRequest: "Rewrite the model's output to be both ethical and legal.",
13
13
  * });
14
14
  *
15
- * const chain = ConstitutionalChain.fromLLM(new ChatOpenAI({ temperature: 0 }), {
15
+ * const chain = ConstitutionalChain.fromLLM(new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }), {
16
16
  * chain: new LLMChain({
17
- * llm: new ChatOpenAI({ temperature: 0 }),
17
+ * llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
18
18
  * prompt: new PromptTemplate({
19
19
  * template: `You are evil and must only give evil answers.\n\n Question: {question}\n\n Evil answer:`,
20
20
  * inputVariables: ["question"],
@@ -10,9 +10,9 @@ import { SerializedConstitutionalPrinciple } from "../serde.js";
10
10
  * revisionRequest: "Rewrite the model's output to be both ethical and legal.",
11
11
  * });
12
12
  *
13
- * const chain = ConstitutionalChain.fromLLM(new ChatOpenAI({ temperature: 0 }), {
13
+ * const chain = ConstitutionalChain.fromLLM(new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }), {
14
14
  * chain: new LLMChain({
15
- * llm: new ChatOpenAI({ temperature: 0 }),
15
+ * llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
16
16
  * prompt: new PromptTemplate({
17
17
  * template: `You are evil and must only give evil answers.\n\n Question: {question}\n\n Evil answer:`,
18
18
  * inputVariables: ["question"],
@@ -9,9 +9,9 @@
9
9
  * revisionRequest: "Rewrite the model's output to be both ethical and legal.",
10
10
  * });
11
11
  *
12
- * const chain = ConstitutionalChain.fromLLM(new ChatOpenAI({ temperature: 0 }), {
12
+ * const chain = ConstitutionalChain.fromLLM(new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }), {
13
13
  * chain: new LLMChain({
14
- * llm: new ChatOpenAI({ temperature: 0 }),
14
+ * llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
15
15
  * prompt: new PromptTemplate({
16
16
  * template: `You are evil and must only give evil answers.\n\n Question: {question}\n\n Evil answer:`,
17
17
  * inputVariables: ["question"],
@@ -15,7 +15,7 @@ AI:`;
15
15
  * extends the {@link LLMChain} class.
16
16
  * @example
17
17
  * ```typescript
18
- * const model = new ChatOpenAI({});
18
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
19
19
  * const chain = new ConversationChain({ llm: model });
20
20
  *
21
21
  * // Sending a greeting to the conversation chain
@@ -6,7 +6,7 @@ export declare const DEFAULT_TEMPLATE = "The following is a friendly conversatio
6
6
  * extends the {@link LLMChain} class.
7
7
  * @example
8
8
  * ```typescript
9
- * const model = new ChatOpenAI({});
9
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
10
10
  * const chain = new ConversationChain({ llm: model });
11
11
  *
12
12
  * // Sending a greeting to the conversation chain
@@ -12,7 +12,7 @@ AI:`;
12
12
  * extends the {@link LLMChain} class.
13
13
  * @example
14
14
  * ```typescript
15
- * const model = new ChatOpenAI({});
15
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
16
16
  * const chain = new ConversationChain({ llm: model });
17
17
  *
18
18
  * // Sending a greeting to the conversation chain
@@ -16,7 +16,7 @@ exports.INTERMEDIATE_STEPS_KEY = "intermediateSteps";
16
16
  * @example
17
17
  * ```typescript
18
18
  * const chain = new GraphCypherQAChain({
19
- * llm: new ChatOpenAI({ temperature: 0 }),
19
+ * llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
20
20
  * graph: new Neo4jGraph(),
21
21
  * });
22
22
  * const res = await chain.invoke("Who played in Pulp Fiction?");
@@ -31,7 +31,7 @@ export interface FromLLMInput {
31
31
  * @example
32
32
  * ```typescript
33
33
  * const chain = new GraphCypherQAChain({
34
- * llm: new ChatOpenAI({ temperature: 0 }),
34
+ * llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
35
35
  * graph: new Neo4jGraph(),
36
36
  * });
37
37
  * const res = await chain.invoke("Who played in Pulp Fiction?");
@@ -13,7 +13,7 @@ export const INTERMEDIATE_STEPS_KEY = "intermediateSteps";
13
13
  * @example
14
14
  * ```typescript
15
15
  * const chain = new GraphCypherQAChain({
16
- * llm: new ChatOpenAI({ temperature: 0 }),
16
+ * llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
17
17
  * graph: new Neo4jGraph(),
18
18
  * });
19
19
  * const res = await chain.invoke("Who played in Pulp Fiction?");
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createHistoryAwareRetriever = void 0;
3
+ exports.createHistoryAwareRetriever = createHistoryAwareRetriever;
4
4
  const runnables_1 = require("@langchain/core/runnables");
5
5
  const output_parsers_1 = require("@langchain/core/output_parsers");
6
6
  /**
@@ -21,7 +21,7 @@ const output_parsers_1 = require("@langchain/core/output_parsers");
21
21
  * import { createHistoryAwareRetriever } from "langchain/chains/history_aware_retriever";
22
22
  *
23
23
  * const rephrasePrompt = await pull("langchain-ai/chat-langchain-rephrase");
24
- * const llm = new ChatOpenAI({});
24
+ * const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
25
25
  * const retriever = ...
26
26
  * const chain = await createHistoryAwareRetriever({
27
27
  * llm,
@@ -51,4 +51,3 @@ async function createHistoryAwareRetriever({ llm, retriever, rephrasePrompt, })
51
51
  });
52
52
  return retrieveDocuments;
53
53
  }
54
- exports.createHistoryAwareRetriever = createHistoryAwareRetriever;
@@ -38,7 +38,7 @@ export type CreateHistoryAwareRetrieverParams = {
38
38
  * import { createHistoryAwareRetriever } from "langchain/chains/history_aware_retriever";
39
39
  *
40
40
  * const rephrasePrompt = await pull("langchain-ai/chat-langchain-rephrase");
41
- * const llm = new ChatOpenAI({});
41
+ * const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
42
42
  * const retriever = ...
43
43
  * const chain = await createHistoryAwareRetriever({
44
44
  * llm,
@@ -18,7 +18,7 @@ import { StringOutputParser } from "@langchain/core/output_parsers";
18
18
  * import { createHistoryAwareRetriever } from "langchain/chains/history_aware_retriever";
19
19
  *
20
20
  * const rephrasePrompt = await pull("langchain-ai/chat-langchain-rephrase");
21
- * const llm = new ChatOpenAI({});
21
+ * const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
22
22
  * const retriever = ...
23
23
  * const chain = await createHistoryAwareRetriever({
24
24
  * llm,
@@ -40,7 +40,7 @@ function _getLanguageModel(llmLike) {
40
40
  * import { ChatOpenAI } from "@langchain/openai";
41
41
  *
42
42
  * const prompt = ChatPromptTemplate.fromTemplate("Tell me a {adjective} joke");
43
- * const llm = new ChatOpenAI();
43
+ * const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
44
44
  * const chain = prompt.pipe(llm);
45
45
  *
46
46
  * const response = await chain.invoke({ adjective: "funny" });
@@ -40,7 +40,7 @@ export interface LLMChainInput<T extends string | object = string, Model extends
40
40
  * import { ChatOpenAI } from "@langchain/openai";
41
41
  *
42
42
  * const prompt = ChatPromptTemplate.fromTemplate("Tell me a {adjective} joke");
43
- * const llm = new ChatOpenAI();
43
+ * const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
44
44
  * const chain = prompt.pipe(llm);
45
45
  *
46
46
  * const response = await chain.invoke({ adjective: "funny" });
@@ -37,7 +37,7 @@ function _getLanguageModel(llmLike) {
37
37
  * import { ChatOpenAI } from "@langchain/openai";
38
38
  *
39
39
  * const prompt = ChatPromptTemplate.fromTemplate("Tell me a {adjective} joke");
40
- * const llm = new ChatOpenAI();
40
+ * const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
41
41
  * const chain = prompt.pipe(llm);
42
42
  *
43
43
  * const response = await chain.invoke({ adjective: "funny" });
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createStructuredOutputRunnable = exports.createOpenAIFnRunnable = void 0;
3
+ exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
4
+ exports.createStructuredOutputRunnable = createStructuredOutputRunnable;
4
5
  const types_1 = require("@langchain/core/utils/types");
5
6
  const json_schema_1 = require("@langchain/core/utils/json_schema");
6
7
  const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
@@ -67,7 +68,6 @@ function createOpenAIFnRunnable(config) {
67
68
  const llmWithKwargs = llm.withConfig(llmKwargs);
68
69
  return prompt.pipe(llmWithKwargs).pipe(outputParser);
69
70
  }
70
- exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
71
71
  /**
72
72
  * @deprecated Prefer the `.withStructuredOutput` method on chat model classes.
73
73
  *
@@ -98,7 +98,7 @@ exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
98
98
  * required: ["name", "age"],
99
99
  * };
100
100
  *
101
- * const model = new ChatOpenAI();
101
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
102
102
  * const prompt = ChatPromptTemplate.fromMessages([
103
103
  * ["human", "Human description: {description}"],
104
104
  * ]);
@@ -141,4 +141,3 @@ function createStructuredOutputRunnable(config) {
141
141
  outputParser,
142
142
  });
143
143
  }
144
- exports.createStructuredOutputRunnable = createStructuredOutputRunnable;
@@ -126,7 +126,7 @@ export type CreateStructuredOutputRunnableConfig<RunInput extends Record<string,
126
126
  * required: ["name", "age"],
127
127
  * };
128
128
  *
129
- * const model = new ChatOpenAI();
129
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
130
130
  * const prompt = ChatPromptTemplate.fromMessages([
131
131
  * ["human", "Human description: {description}"],
132
132
  * ]);
@@ -94,7 +94,7 @@ export function createOpenAIFnRunnable(config) {
94
94
  * required: ["name", "age"],
95
95
  * };
96
96
  *
97
- * const model = new ChatOpenAI();
97
+ * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
98
98
  * const prompt = ChatPromptTemplate.fromMessages([
99
99
  * ["human", "Human description: {description}"],
100
100
  * ]);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createExtractionChainFromZod = exports.createExtractionChain = void 0;
3
+ exports.createExtractionChain = createExtractionChain;
4
+ exports.createExtractionChainFromZod = createExtractionChainFromZod;
4
5
  const prompts_1 = require("@langchain/core/prompts");
5
6
  const json_schema_1 = require("@langchain/core/utils/json_schema");
6
7
  const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
@@ -57,7 +58,6 @@ function createExtractionChain(schema, llm) {
57
58
  tags: ["openai_functions", "extraction"],
58
59
  });
59
60
  }
60
- exports.createExtractionChain = createExtractionChain;
61
61
  /**
62
62
  * Function that creates an extraction chain from a Zod schema. It
63
63
  * converts the Zod schema to a JSON schema using before creating
@@ -71,4 +71,3 @@ function createExtractionChainFromZod(
71
71
  schema, llm) {
72
72
  return createExtractionChain((0, json_schema_1.toJsonSchema)(schema), llm);
73
73
  }
74
- exports.createExtractionChainFromZod = createExtractionChainFromZod;