langchain 0.3.27 → 0.3.29

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 (126) hide show
  1. package/dist/agents/agent.cjs +36 -3
  2. package/dist/agents/format_scratchpad/log.cjs +1 -2
  3. package/dist/agents/format_scratchpad/log_to_message.cjs +1 -2
  4. package/dist/agents/format_scratchpad/openai_functions.cjs +2 -3
  5. package/dist/agents/format_scratchpad/tool_calling.cjs +2 -3
  6. package/dist/agents/format_scratchpad/xml.cjs +1 -2
  7. package/dist/agents/initialize.cjs +2 -2
  8. package/dist/agents/openai_functions/index.cjs +3 -3
  9. package/dist/agents/openai_tools/index.cjs +2 -2
  10. package/dist/agents/react/index.cjs +1 -2
  11. package/dist/agents/structured_chat/index.cjs +6 -4
  12. package/dist/agents/structured_chat/index.js +5 -3
  13. package/dist/agents/structured_chat/prompt.d.ts +1 -1
  14. package/dist/agents/tool_calling/index.cjs +1 -2
  15. package/dist/agents/tool_calling/output_parser.cjs +2 -2
  16. package/dist/agents/toolkits/conversational_retrieval/openai_functions.cjs +1 -2
  17. package/dist/agents/toolkits/conversational_retrieval/tool.cjs +1 -2
  18. package/dist/agents/toolkits/json/json.cjs +2 -2
  19. package/dist/agents/toolkits/openapi/openapi.cjs +2 -2
  20. package/dist/agents/toolkits/sql/sql.cjs +2 -2
  21. package/dist/agents/toolkits/vectorstore/vectorstore.cjs +3 -3
  22. package/dist/agents/xml/index.cjs +2 -2
  23. package/dist/chains/api/prompts.d.ts +1 -1
  24. package/dist/chains/base.cjs +42 -9
  25. package/dist/chains/base.d.ts +2 -2
  26. package/dist/chains/base.js +1 -1
  27. package/dist/chains/combine_documents/base.cjs +2 -2
  28. package/dist/chains/combine_documents/reduce.cjs +2 -3
  29. package/dist/chains/combine_documents/stuff.cjs +1 -2
  30. package/dist/chains/history_aware_retriever.cjs +1 -2
  31. package/dist/chains/openai_functions/base.cjs +5 -6
  32. package/dist/chains/openai_functions/base.d.ts +3 -4
  33. package/dist/chains/openai_functions/base.js +4 -4
  34. package/dist/chains/openai_functions/extraction.cjs +6 -7
  35. package/dist/chains/openai_functions/extraction.d.ts +4 -4
  36. package/dist/chains/openai_functions/extraction.js +4 -4
  37. package/dist/chains/openai_functions/openapi.cjs +4 -5
  38. package/dist/chains/openai_functions/openapi.d.ts +1 -1
  39. package/dist/chains/openai_functions/openapi.js +1 -1
  40. package/dist/chains/openai_functions/structured_output.cjs +7 -7
  41. package/dist/chains/openai_functions/structured_output.d.ts +7 -8
  42. package/dist/chains/openai_functions/structured_output.js +5 -5
  43. package/dist/chains/openai_functions/tagging.cjs +4 -5
  44. package/dist/chains/openai_functions/tagging.d.ts +2 -2
  45. package/dist/chains/openai_functions/tagging.js +2 -2
  46. package/dist/chains/query_constructor/index.cjs +3 -3
  47. package/dist/chains/query_constructor/index.d.ts +2 -2
  48. package/dist/chains/question_answering/load.cjs +4 -4
  49. package/dist/chains/retrieval.cjs +1 -2
  50. package/dist/chains/router/utils.cjs +1 -2
  51. package/dist/chains/sequential_chain.cjs +2 -1
  52. package/dist/chains/sequential_chain.js +2 -1
  53. package/dist/chains/sql_db/sql_db_chain.cjs +2 -2
  54. package/dist/chat_models/universal.cjs +54 -21
  55. package/dist/document_loaders/fs/buffer.cjs +34 -1
  56. package/dist/document_loaders/fs/buffer.d.ts +0 -3
  57. package/dist/document_loaders/fs/directory.cjs +35 -2
  58. package/dist/document_loaders/fs/directory.d.ts +0 -2
  59. package/dist/document_loaders/fs/text.cjs +34 -1
  60. package/dist/document_loaders/fs/text.d.ts +0 -1
  61. package/dist/document_transformers/openai_functions.cjs +5 -5
  62. package/dist/document_transformers/openai_functions.d.ts +3 -3
  63. package/dist/document_transformers/openai_functions.js +2 -2
  64. package/dist/evaluation/embedding_distance/base.cjs +3 -3
  65. package/dist/evaluation/loader.cjs +1 -2
  66. package/dist/experimental/autogpt/output_parser.cjs +2 -2
  67. package/dist/experimental/autogpt/prompt_generator.cjs +4 -4
  68. package/dist/experimental/autogpt/prompt_generator.js +3 -3
  69. package/dist/experimental/generative_agents/generative_agent.cjs +1 -1
  70. package/dist/experimental/generative_agents/generative_agent.js +1 -1
  71. package/dist/experimental/openai_assistant/index.cjs +8 -4
  72. package/dist/experimental/openai_assistant/index.d.ts +6 -6
  73. package/dist/experimental/openai_assistant/index.js +9 -5
  74. package/dist/experimental/openai_files/index.cjs +2 -2
  75. package/dist/experimental/openai_files/index.d.ts +6 -4
  76. package/dist/experimental/openai_files/index.js +2 -2
  77. package/dist/experimental/plan_and_execute/agent_executor.cjs +2 -2
  78. package/dist/hub/base.cjs +4 -5
  79. package/dist/hub/index.cjs +2 -2
  80. package/dist/hub/node.cjs +43 -10
  81. package/dist/index.cjs +0 -1
  82. package/dist/index.d.ts +0 -1
  83. package/dist/index.js +1 -1
  84. package/dist/load/import_map.cjs +17 -7
  85. package/dist/load/index.cjs +18 -9
  86. package/dist/output_parsers/expression_type_handlers/base.cjs +34 -1
  87. package/dist/output_parsers/openai_functions.d.ts +1 -1
  88. package/dist/output_parsers/router.d.ts +3 -3
  89. package/dist/output_parsers/structured.cjs +6 -5
  90. package/dist/output_parsers/structured.d.ts +9 -8
  91. package/dist/output_parsers/structured.js +6 -5
  92. package/dist/prompts/index.cjs +0 -1
  93. package/dist/prompts/index.d.ts +0 -1
  94. package/dist/prompts/index.js +1 -1
  95. package/dist/retrievers/hyde.cjs +2 -2
  96. package/dist/retrievers/parent_document.cjs +17 -7
  97. package/dist/smith/config.cjs +5 -6
  98. package/dist/smith/name_generation.cjs +1 -2
  99. package/dist/smith/runner_utils.cjs +1 -2
  100. package/dist/sql_db.cjs +35 -2
  101. package/dist/storage/encoder_backed.cjs +2 -2
  102. package/dist/storage/encoder_backed.d.ts +1 -1
  103. package/dist/storage/file_system.cjs +17 -7
  104. package/dist/storage/file_system.d.ts +1 -1
  105. package/dist/stores/file/node.cjs +17 -7
  106. package/dist/tools/convert_to_openai.cjs +5 -5
  107. package/dist/tools/convert_to_openai.js +4 -4
  108. package/dist/tools/fs.d.ts +3 -2
  109. package/dist/tools/render.cjs +6 -5
  110. package/dist/tools/render.js +5 -3
  111. package/dist/tools/retriever.cjs +1 -2
  112. package/dist/tools/webbrowser.cjs +17 -7
  113. package/dist/util/axios-fetch-adapter.cjs +1 -1
  114. package/dist/util/azure.cjs +1 -2
  115. package/dist/util/entrypoint_deprecation.cjs +2 -3
  116. package/dist/util/load.cjs +34 -1
  117. package/dist/util/ml-distance/distances.cjs +3 -4
  118. package/dist/util/ml-distance/similarities.cjs +1 -2
  119. package/dist/util/ml-distance-euclidean/euclidean.cjs +2 -3
  120. package/dist/util/openapi.cjs +17 -7
  121. package/dist/util/openapi.d.ts +32 -32
  122. package/dist/util/parse.cjs +17 -7
  123. package/dist/util/prompt-layer.d.ts +1 -1
  124. package/dist/util/set.cjs +3 -4
  125. package/dist/util/time.cjs +1 -2
  126. package/package.json +8 -9
@@ -1,8 +1,9 @@
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
- const zod_to_json_schema_1 = require("zod-to-json-schema");
6
+ const json_schema_1 = require("@langchain/core/utils/json_schema");
6
7
  const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
7
8
  /**
8
9
  * Creates a runnable sequence that calls OpenAI functions.
@@ -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
  *
@@ -125,8 +125,8 @@ exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
125
125
  */
126
126
  function createStructuredOutputRunnable(config) {
127
127
  const { outputSchema, llm, prompt, outputParser } = config;
128
- const jsonSchema = (0, types_1.isZodSchema)(outputSchema)
129
- ? (0, zod_to_json_schema_1.zodToJsonSchema)(outputSchema)
128
+ const jsonSchema = (0, types_1.isInteropZodSchema)(outputSchema)
129
+ ? (0, json_schema_1.toJsonSchema)(outputSchema)
130
130
  : outputSchema;
131
131
  const oaiFunction = {
132
132
  name: "outputFormatter",
@@ -141,4 +141,3 @@ function createStructuredOutputRunnable(config) {
141
141
  outputParser,
142
142
  });
143
143
  }
144
- exports.createStructuredOutputRunnable = createStructuredOutputRunnable;
@@ -1,11 +1,10 @@
1
- import type { z } from "zod";
2
1
  import type { BaseOutputParser } from "@langchain/core/output_parsers";
3
2
  import type { BasePromptTemplate } from "@langchain/core/prompts";
4
3
  import type { Runnable, RunnableInterface } from "@langchain/core/runnables";
5
4
  import type { BaseFunctionCallOptions, BaseLanguageModelInput, FunctionDefinition } from "@langchain/core/language_models/base";
6
- import { type InputValues } from "@langchain/core/utils/types";
5
+ import { type InputValues, InteropZodObject } from "@langchain/core/utils/types";
7
6
  import type { BaseMessage } from "@langchain/core/messages";
8
- import { type JsonSchema7Type } from "zod-to-json-schema";
7
+ import { type JsonSchema7Type } from "@langchain/core/utils/json_schema";
9
8
  /**
10
9
  * Configuration params for the createOpenAIFnRunnable method.
11
10
  */
@@ -85,7 +84,7 @@ export type CreateStructuredOutputRunnableConfig<RunInput extends Record<string,
85
84
  /**
86
85
  * Schema to output. Must be either valid JSONSchema or a Zod schema.
87
86
  */
88
- outputSchema: z.AnyZodObject | JsonSchema7Type;
87
+ outputSchema: InteropZodObject | JsonSchema7Type;
89
88
  /**
90
89
  * Language model to use, assumed to support the OpenAI function-calling API.
91
90
  */
@@ -1,5 +1,5 @@
1
- import { isZodSchema } from "@langchain/core/utils/types";
2
- import { zodToJsonSchema } from "zod-to-json-schema";
1
+ import { isInteropZodSchema, } from "@langchain/core/utils/types";
2
+ import { toJsonSchema, } from "@langchain/core/utils/json_schema";
3
3
  import { JsonOutputFunctionsParser } from "../../output_parsers/openai_functions.js";
4
4
  /**
5
5
  * Creates a runnable sequence that calls OpenAI functions.
@@ -121,8 +121,8 @@ export function createOpenAIFnRunnable(config) {
121
121
  */
122
122
  export function createStructuredOutputRunnable(config) {
123
123
  const { outputSchema, llm, prompt, outputParser } = config;
124
- const jsonSchema = isZodSchema(outputSchema)
125
- ? zodToJsonSchema(outputSchema)
124
+ const jsonSchema = isInteropZodSchema(outputSchema)
125
+ ? toJsonSchema(outputSchema)
126
126
  : outputSchema;
127
127
  const oaiFunction = {
128
128
  name: "outputFormatter",
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createExtractionChainFromZod = exports.createExtractionChain = void 0;
4
- const zod_to_json_schema_1 = require("zod-to-json-schema");
3
+ exports.createExtractionChain = createExtractionChain;
4
+ exports.createExtractionChainFromZod = createExtractionChainFromZod;
5
5
  const prompts_1 = require("@langchain/core/prompts");
6
+ const json_schema_1 = require("@langchain/core/utils/json_schema");
6
7
  const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
7
8
  const llm_chain_js_1 = require("../llm_chain.cjs");
8
9
  /**
@@ -57,11 +58,10 @@ 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
- * converts the Zod schema to a JSON schema using zod-to-json-schema
64
- * before creating the extraction chain.
63
+ * converts the Zod schema to a JSON schema using before creating
64
+ * the extraction chain.
65
65
  * @param schema The Zod schema which extracted data should match
66
66
  * @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
67
67
  * @returns A LLMChain instance configured to return data matching the schema.
@@ -69,6 +69,5 @@ exports.createExtractionChain = createExtractionChain;
69
69
  function createExtractionChainFromZod(
70
70
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
71
  schema, llm) {
72
- return createExtractionChain((0, zod_to_json_schema_1.zodToJsonSchema)(schema), llm);
72
+ return createExtractionChain((0, json_schema_1.toJsonSchema)(schema), llm);
73
73
  }
74
- exports.createExtractionChainFromZod = createExtractionChainFromZod;
@@ -1,6 +1,6 @@
1
- import { z } from "zod";
2
1
  import { BaseChatModel } from "@langchain/core/language_models/chat_models";
3
2
  import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
3
+ import { InteropZodObject } from "@langchain/core/utils/types";
4
4
  import { FunctionParameters } from "../../output_parsers/openai_functions.js";
5
5
  import { LLMChain } from "../llm_chain.js";
6
6
  /**
@@ -13,10 +13,10 @@ import { LLMChain } from "../llm_chain.js";
13
13
  export declare function createExtractionChain(schema: FunctionParameters, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
14
14
  /**
15
15
  * Function that creates an extraction chain from a Zod schema. It
16
- * converts the Zod schema to a JSON schema using zod-to-json-schema
17
- * before creating the extraction chain.
16
+ * converts the Zod schema to a JSON schema using before creating
17
+ * the extraction chain.
18
18
  * @param schema The Zod schema which extracted data should match
19
19
  * @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
20
20
  * @returns A LLMChain instance configured to return data matching the schema.
21
21
  */
22
- export declare function createExtractionChainFromZod(schema: z.ZodObject<any, any, any, any>, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
22
+ export declare function createExtractionChainFromZod(schema: InteropZodObject, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
@@ -1,5 +1,5 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
1
  import { PromptTemplate } from "@langchain/core/prompts";
2
+ import { toJsonSchema, } from "@langchain/core/utils/json_schema";
3
3
  import { JsonKeyOutputFunctionsParser, } from "../../output_parsers/openai_functions.js";
4
4
  import { LLMChain } from "../llm_chain.js";
5
5
  /**
@@ -56,8 +56,8 @@ export function createExtractionChain(schema, llm) {
56
56
  }
57
57
  /**
58
58
  * Function that creates an extraction chain from a Zod schema. It
59
- * converts the Zod schema to a JSON schema using zod-to-json-schema
60
- * before creating the extraction chain.
59
+ * converts the Zod schema to a JSON schema using before creating
60
+ * the extraction chain.
61
61
  * @param schema The Zod schema which extracted data should match
62
62
  * @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
63
63
  * @returns A LLMChain instance configured to return data matching the schema.
@@ -65,5 +65,5 @@ export function createExtractionChain(schema, llm) {
65
65
  export function createExtractionChainFromZod(
66
66
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
67
  schema, llm) {
68
- return createExtractionChain(zodToJsonSchema(schema), llm);
68
+ return createExtractionChain(toJsonSchema(schema), llm);
69
69
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createOpenAPIChain = exports.convertOpenAPISpecToOpenAIFunctions = exports.convertOpenAPISchemaToJSONSchema = void 0;
3
+ exports.convertOpenAPISchemaToJSONSchema = convertOpenAPISchemaToJSONSchema;
4
+ exports.convertOpenAPISpecToOpenAIFunctions = convertOpenAPISpecToOpenAIFunctions;
5
+ exports.createOpenAPIChain = createOpenAPIChain;
4
6
  const openai_1 = require("@langchain/openai");
5
7
  const prompts_1 = require("@langchain/core/prompts");
6
8
  const openapi_js_1 = require("../../util/openapi.cjs");
@@ -158,7 +160,6 @@ function convertOpenAPISchemaToJSONSchema(schema, spec) {
158
160
  type: schema.type ?? "string",
159
161
  };
160
162
  }
161
- exports.convertOpenAPISchemaToJSONSchema = convertOpenAPISchemaToJSONSchema;
162
163
  /**
163
164
  * Converts an OpenAPI specification to OpenAI functions.
164
165
  * @param spec The OpenAPI specification to convert.
@@ -302,7 +303,6 @@ function convertOpenAPISpecToOpenAIFunctions(spec) {
302
303
  },
303
304
  };
304
305
  }
305
- exports.convertOpenAPISpecToOpenAIFunctions = convertOpenAPISpecToOpenAIFunctions;
306
306
  /**
307
307
  * A chain for making simple API requests.
308
308
  */
@@ -378,7 +378,7 @@ async function createOpenAPIChain(spec, options = {}) {
378
378
  if (defaultExecutionMethod === undefined) {
379
379
  throw new Error(`Could not parse any valid operations from the provided spec.`);
380
380
  }
381
- const { llm = new openai_1.ChatOpenAI({ modelName: "gpt-3.5-turbo-0613" }), prompt = prompts_1.ChatPromptTemplate.fromMessages([
381
+ const { llm = new openai_1.ChatOpenAI({ model: "gpt-3.5-turbo-0613" }), prompt = prompts_1.ChatPromptTemplate.fromMessages([
382
382
  prompts_1.HumanMessagePromptTemplate.fromTemplate("Use the provided API's to respond to this user query:\n\n{query}"),
383
383
  ]), requestChain = new SimpleRequestChain({
384
384
  requestMethod: async (name, args) => defaultExecutionMethod(name, args, {
@@ -402,4 +402,3 @@ async function createOpenAPIChain(spec, options = {}) {
402
402
  ...rest,
403
403
  });
404
404
  }
405
- exports.createOpenAPIChain = createOpenAPIChain;
@@ -1,5 +1,5 @@
1
1
  import type { OpenAIClient } from "@langchain/openai";
2
- import { JsonSchema7Type } from "zod-to-json-schema";
2
+ import { type JsonSchema7Type } from "@langchain/core/utils/json_schema";
3
3
  import type { OpenAPIV3_1 } from "openapi-types";
4
4
  import { BaseChatModel } from "@langchain/core/language_models/chat_models";
5
5
  import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
@@ -373,7 +373,7 @@ export async function createOpenAPIChain(spec, options = {}) {
373
373
  if (defaultExecutionMethod === undefined) {
374
374
  throw new Error(`Could not parse any valid operations from the provided spec.`);
375
375
  }
376
- const { llm = new ChatOpenAI({ modelName: "gpt-3.5-turbo-0613" }), prompt = ChatPromptTemplate.fromMessages([
376
+ const { llm = new ChatOpenAI({ model: "gpt-3.5-turbo-0613" }), prompt = ChatPromptTemplate.fromMessages([
377
377
  HumanMessagePromptTemplate.fromTemplate("Use the provided API's to respond to this user query:\n\n{query}"),
378
378
  ]), requestChain = new SimpleRequestChain({
379
379
  requestMethod: async (name, args) => defaultExecutionMethod(name, args, {
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createStructuredOutputChainFromZod = exports.createStructuredOutputChain = exports.FunctionCallStructuredOutputParser = void 0;
4
- const zod_to_json_schema_1 = require("zod-to-json-schema");
3
+ exports.FunctionCallStructuredOutputParser = void 0;
4
+ exports.createStructuredOutputChain = createStructuredOutputChain;
5
+ exports.createStructuredOutputChainFromZod = createStructuredOutputChainFromZod;
5
6
  const json_schema_1 = require("@langchain/core/utils/json_schema");
6
7
  const openai_1 = require("@langchain/openai");
7
8
  const output_parsers_1 = require("@langchain/core/output_parsers");
9
+ const types_1 = require("@langchain/core/utils/types");
8
10
  const llm_chain_js_1 = require("../llm_chain.cjs");
9
11
  const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
10
12
  function isJsonSchema7Type(x) {
@@ -78,12 +80,12 @@ class FunctionCallStructuredOutputParser extends output_parsers_1.BaseLLMOutputP
78
80
  return value;
79
81
  });
80
82
  if (this.zodSchema) {
81
- const zodParsedResult = this.zodSchema.safeParse(parsedResult);
83
+ const zodParsedResult = await (0, types_1.interopSafeParseAsync)(this.zodSchema, parsedResult);
82
84
  if (zodParsedResult.success) {
83
85
  return zodParsedResult.data;
84
86
  }
85
87
  else {
86
- throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.errors)}`, initialResult);
88
+ throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, initialResult);
87
89
  }
88
90
  }
89
91
  else if (this.jsonSchemaValidator !== undefined) {
@@ -137,13 +139,11 @@ function createStructuredOutputChain(input) {
137
139
  ...rest,
138
140
  });
139
141
  }
140
- exports.createStructuredOutputChain = createStructuredOutputChain;
141
142
  /** @deprecated Use {@link https://api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
142
143
  function createStructuredOutputChainFromZod(zodSchema, input) {
143
144
  return createStructuredOutputChain({
144
145
  ...input,
145
- outputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(zodSchema),
146
+ outputSchema: (0, json_schema_1.toJsonSchema)(zodSchema),
146
147
  zodSchema,
147
148
  });
148
149
  }
149
- exports.createStructuredOutputChainFromZod = createStructuredOutputChainFromZod;
@@ -1,12 +1,11 @@
1
- import { z } from "zod";
2
- import { JsonSchema7Type } from "zod-to-json-schema";
3
- import { Validator } from "@langchain/core/utils/json_schema";
1
+ import { type JsonSchema7Type, Validator } from "@langchain/core/utils/json_schema";
4
2
  import { ChatOpenAI } from "@langchain/openai";
5
3
  import { BasePromptTemplate } from "@langchain/core/prompts";
6
4
  import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
7
5
  import { ChatGeneration } from "@langchain/core/outputs";
8
6
  import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
9
7
  import type { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
8
+ import { InferInteropZodOutput, InteropZodObject } from "@langchain/core/utils/types";
10
9
  import { LLMChain, type LLMChainInput } from "../llm_chain.js";
11
10
  import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js";
12
11
  /**
@@ -15,13 +14,13 @@ import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js"
15
14
  * 'outputSchema' field representing the JSON schema for the expected
16
15
  * output.
17
16
  */
18
- export type StructuredOutputChainInput<T extends z.AnyZodObject = z.AnyZodObject> = Omit<LLMChainInput, "outputParser" | "llm"> & {
17
+ export type StructuredOutputChainInput<T extends InteropZodObject = InteropZodObject> = Omit<LLMChainInput, "outputParser" | "llm"> & {
19
18
  outputSchema?: JsonSchema7Type;
20
19
  prompt: BasePromptTemplate;
21
20
  llm?: BaseChatModel<BaseFunctionCallOptions>;
22
21
  zodSchema?: T;
23
22
  };
24
- export type FunctionCallStructuredOutputParserFields<T extends z.AnyZodObject = z.AnyZodObject> = {
23
+ export type FunctionCallStructuredOutputParserFields<T extends InteropZodObject = InteropZodObject> = {
25
24
  jsonSchema?: JsonSchema7Type;
26
25
  zodSchema?: T;
27
26
  };
@@ -29,7 +28,7 @@ export type FunctionCallStructuredOutputParserFields<T extends z.AnyZodObject =
29
28
  * Class that extends the BaseLLMOutputParser class. It provides
30
29
  * functionality for parsing the structured output based on a JSON schema.
31
30
  */
32
- export declare class FunctionCallStructuredOutputParser<T extends z.AnyZodObject> extends BaseLLMOutputParser<z.infer<T>> {
31
+ export declare class FunctionCallStructuredOutputParser<T extends InteropZodObject> extends BaseLLMOutputParser<InferInteropZodOutput<T>> {
33
32
  lc_namespace: string[];
34
33
  protected functionOutputParser: OutputFunctionsParser;
35
34
  protected jsonSchemaValidator?: Validator;
@@ -55,6 +54,6 @@ export declare class FunctionCallStructuredOutputParser<T extends z.AnyZodObject
55
54
  * as well as an additional required "outputSchema" JSON Schema object.
56
55
  * @returns OpenAPIChain
57
56
  */
58
- export declare function createStructuredOutputChain<T extends z.AnyZodObject = z.AnyZodObject>(input: StructuredOutputChainInput<T>): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
57
+ export declare function createStructuredOutputChain<T extends InteropZodObject = InteropZodObject>(input: StructuredOutputChainInput<T>): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
59
58
  /** @deprecated Use {@link https://api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
60
- export declare function createStructuredOutputChainFromZod<T extends z.AnyZodObject>(zodSchema: T, input: Omit<StructuredOutputChainInput<T>, "outputSchema">): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
59
+ export declare function createStructuredOutputChainFromZod<T extends InteropZodObject>(zodSchema: T, input: Omit<StructuredOutputChainInput<T>, "outputSchema">): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
@@ -1,7 +1,7 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
- import { Validator } from "@langchain/core/utils/json_schema";
1
+ import { Validator, toJsonSchema, } from "@langchain/core/utils/json_schema";
3
2
  import { ChatOpenAI } from "@langchain/openai";
4
3
  import { BaseLLMOutputParser, OutputParserException, } from "@langchain/core/output_parsers";
4
+ import { interopSafeParseAsync, } from "@langchain/core/utils/types";
5
5
  import { LLMChain } from "../llm_chain.js";
6
6
  import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js";
7
7
  function isJsonSchema7Type(x) {
@@ -75,12 +75,12 @@ export class FunctionCallStructuredOutputParser extends BaseLLMOutputParser {
75
75
  return value;
76
76
  });
77
77
  if (this.zodSchema) {
78
- const zodParsedResult = this.zodSchema.safeParse(parsedResult);
78
+ const zodParsedResult = await interopSafeParseAsync(this.zodSchema, parsedResult);
79
79
  if (zodParsedResult.success) {
80
80
  return zodParsedResult.data;
81
81
  }
82
82
  else {
83
- throw new OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.errors)}`, initialResult);
83
+ throw new OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, initialResult);
84
84
  }
85
85
  }
86
86
  else if (this.jsonSchemaValidator !== undefined) {
@@ -137,7 +137,7 @@ export function createStructuredOutputChain(input) {
137
137
  export function createStructuredOutputChainFromZod(zodSchema, input) {
138
138
  return createStructuredOutputChain({
139
139
  ...input,
140
- outputSchema: zodToJsonSchema(zodSchema),
140
+ outputSchema: toJsonSchema(zodSchema),
141
141
  zodSchema,
142
142
  });
143
143
  }
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTaggingChainFromZod = exports.createTaggingChain = void 0;
4
- const zod_to_json_schema_1 = require("zod-to-json-schema");
3
+ exports.createTaggingChain = createTaggingChain;
4
+ exports.createTaggingChainFromZod = createTaggingChainFromZod;
5
5
  const prompts_1 = require("@langchain/core/prompts");
6
+ const json_schema_1 = require("@langchain/core/utils/json_schema");
6
7
  const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
7
8
  const llm_chain_js_1 = require("../llm_chain.cjs");
8
9
  /**
@@ -51,7 +52,6 @@ function createTaggingChain(schema, llm, options = {}) {
51
52
  ...rest,
52
53
  });
53
54
  }
54
- exports.createTaggingChain = createTaggingChain;
55
55
  /**
56
56
  * Function that creates a tagging chain from a Zod schema. It converts
57
57
  * the Zod schema to a JSON schema using the zodToJsonSchema function and
@@ -68,6 +68,5 @@ exports.createTaggingChain = createTaggingChain;
68
68
  function createTaggingChainFromZod(
69
69
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
70
  schema, llm, options) {
71
- return createTaggingChain((0, zod_to_json_schema_1.zodToJsonSchema)(schema), llm, options);
71
+ return createTaggingChain((0, json_schema_1.toJsonSchema)(schema), llm, options);
72
72
  }
73
- exports.createTaggingChainFromZod = createTaggingChainFromZod;
@@ -1,7 +1,7 @@
1
- import { z } from "zod";
2
1
  import { BaseChatModel } from "@langchain/core/language_models/chat_models";
3
2
  import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
4
3
  import { PromptTemplate } from "@langchain/core/prompts";
4
+ import { InteropZodObject } from "@langchain/core/utils/types";
5
5
  import { FunctionParameters } from "../../output_parsers/openai_functions.js";
6
6
  import { LLMChain, LLMChainInput } from "../llm_chain.js";
7
7
  /**
@@ -37,4 +37,4 @@ export declare function createTaggingChain(schema: FunctionParameters, llm: Base
37
37
  * Switch to expression language: https://js.langchain.com/docs/expression_language/
38
38
  * Will be removed in 0.2.0
39
39
  */
40
- export declare function createTaggingChainFromZod(schema: z.ZodObject<any, any, any, any>, llm: BaseChatModel<BaseFunctionCallOptions>, options?: TaggingChainOptions): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
40
+ export declare function createTaggingChainFromZod(schema: InteropZodObject, llm: BaseChatModel<BaseFunctionCallOptions>, options?: TaggingChainOptions): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
@@ -1,5 +1,5 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
1
  import { PromptTemplate } from "@langchain/core/prompts";
2
+ import { toJsonSchema, } from "@langchain/core/utils/json_schema";
3
3
  import { JsonOutputFunctionsParser, } from "../../output_parsers/openai_functions.js";
4
4
  import { LLMChain } from "../llm_chain.js";
5
5
  /**
@@ -64,5 +64,5 @@ export function createTaggingChain(schema, llm, options = {}) {
64
64
  export function createTaggingChainFromZod(
65
65
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
66
  schema, llm, options) {
67
- return createTaggingChain(zodToJsonSchema(schema), llm, options);
67
+ return createTaggingChain(toJsonSchema(schema), llm, options);
68
68
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadQueryConstructorRunnable = exports.formatAttributeInfo = exports.StructuredQueryOutputParser = exports.EXAMPLE_PROMPT = exports.DEFAULT_SUFFIX = exports.DEFAULT_SCHEMA = exports.DEFAULT_PREFIX = exports.DEFAULT_EXAMPLES = exports.QueryTransformer = exports.AttributeInfo = void 0;
3
+ exports.StructuredQueryOutputParser = exports.EXAMPLE_PROMPT = exports.DEFAULT_SUFFIX = exports.DEFAULT_SCHEMA = exports.DEFAULT_PREFIX = exports.DEFAULT_EXAMPLES = exports.QueryTransformer = exports.AttributeInfo = void 0;
4
+ exports.formatAttributeInfo = formatAttributeInfo;
5
+ exports.loadQueryConstructorRunnable = loadQueryConstructorRunnable;
4
6
  const zod_1 = require("zod");
5
7
  const prompts_1 = require("@langchain/core/prompts");
6
8
  const parser_js_1 = require("./parser.cjs");
@@ -118,7 +120,6 @@ function formatAttributeInfo(info) {
118
120
  .replaceAll("{", "{{")
119
121
  .replaceAll("}", "}}");
120
122
  }
121
- exports.formatAttributeInfo = formatAttributeInfo;
122
123
  const defaultExample = prompt_js_1.DEFAULT_EXAMPLES.map((EXAMPLE) => EXAMPLE);
123
124
  function _getPrompt(documentContents, attributeInfo, allowedComparators, allowedOperators, examples = defaultExample) {
124
125
  const myAllowedComparators = allowedComparators ?? Object.values(ir_js_1.Comparators);
@@ -151,4 +152,3 @@ function loadQueryConstructorRunnable(opts) {
151
152
  const outputParser = StructuredQueryOutputParser.fromComponents(opts.allowedComparators, opts.allowedOperators);
152
153
  return prompt.pipe(opts.llm).pipe(outputParser);
153
154
  }
154
- exports.loadQueryConstructorRunnable = loadQueryConstructorRunnable;
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base";
3
- import { InputValues } from "@langchain/core/utils/types";
3
+ import { InferInteropZodOutput, InputValues } from "@langchain/core/utils/types";
4
4
  import { QueryTransformer, TraverseType } from "./parser.js";
5
5
  import { Comparator, Operator, StructuredQuery } from "./ir.js";
6
6
  import { DEFAULT_EXAMPLES, DEFAULT_PREFIX, DEFAULT_SCHEMA, DEFAULT_SUFFIX, EXAMPLE_PROMPT } from "./prompt.js";
@@ -45,7 +45,7 @@ export declare class StructuredQueryOutputParser extends AsymmetricStructuredOut
45
45
  * @param filter The filter condition.
46
46
  * @returns A Promise that resolves to a StructuredQuery instance.
47
47
  */
48
- outputProcessor({ query, filter, }: z.infer<typeof queryInputSchema>): Promise<StructuredQuery>;
48
+ outputProcessor({ query, filter, }: InferInteropZodOutput<typeof queryInputSchema>): Promise<StructuredQuery>;
49
49
  /**
50
50
  * Creates a new StructuredQueryOutputParser instance from the provided
51
51
  * components.
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadQARefineChain = exports.loadQAMapReduceChain = exports.loadQAStuffChain = exports.loadQAChain = void 0;
3
+ exports.loadQAChain = void 0;
4
+ exports.loadQAStuffChain = loadQAStuffChain;
5
+ exports.loadQAMapReduceChain = loadQAMapReduceChain;
6
+ exports.loadQARefineChain = loadQARefineChain;
4
7
  const llm_chain_js_1 = require("../llm_chain.cjs");
5
8
  const combine_docs_chain_js_1 = require("../combine_docs_chain.cjs");
6
9
  const stuff_prompts_js_1 = require("./stuff_prompts.cjs");
@@ -33,7 +36,6 @@ function loadQAStuffChain(llm, params = {}) {
33
36
  const chain = new combine_docs_chain_js_1.StuffDocumentsChain({ llmChain, verbose });
34
37
  return chain;
35
38
  }
36
- exports.loadQAStuffChain = loadQAStuffChain;
37
39
  /**
38
40
  * Loads a MapReduceQAChain based on the provided parameters. It takes an
39
41
  * LLM instance and MapReduceQAChainParams as parameters.
@@ -62,7 +64,6 @@ function loadQAMapReduceChain(llm, params = {}) {
62
64
  });
63
65
  return chain;
64
66
  }
65
- exports.loadQAMapReduceChain = loadQAMapReduceChain;
66
67
  /**
67
68
  * Loads a RefineQAChain based on the provided parameters. It takes an LLM
68
69
  * instance and RefineQAChainParams as parameters.
@@ -85,4 +86,3 @@ function loadQARefineChain(llm, params = {}) {
85
86
  });
86
87
  return chain;
87
88
  }
88
- exports.loadQARefineChain = loadQARefineChain;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRetrievalChain = void 0;
3
+ exports.createRetrievalChain = createRetrievalChain;
4
4
  const runnables_1 = require("@langchain/core/runnables");
5
5
  function isBaseRetriever(x) {
6
6
  return (!!x &&
@@ -57,4 +57,3 @@ async function createRetrievalChain({ retriever, combineDocsChain, }) {
57
57
  ]).withConfig({ runName: "retrieval_chain" });
58
58
  return retrievalChain;
59
59
  }
60
- exports.createRetrievalChain = createRetrievalChain;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zipEntries = void 0;
3
+ exports.zipEntries = zipEntries;
4
4
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
5
  function zipEntries(...arrays) {
6
6
  // Check for empty input
@@ -31,4 +31,3 @@ function zipEntries(...arrays) {
31
31
  }
32
32
  return zipped;
33
33
  }
34
- exports.zipEntries = zipEntries;
@@ -275,7 +275,8 @@ class SimpleSequentialChain extends base_js_1.BaseChain {
275
275
  /** @ignore */
276
276
  _validateChains() {
277
277
  for (const chain of this.chains) {
278
- if (chain.inputKeys.filter((k) => !chain.memory?.memoryKeys.includes(k) ?? true).length !== 1) {
278
+ if (chain.inputKeys.filter((k) => !chain.memory?.memoryKeys.includes(k))
279
+ .length !== 1) {
279
280
  throw new Error(`Chains used in SimpleSequentialChain should all have one input, got ${chain.inputKeys.length} for ${chain._chainType()}.`);
280
281
  }
281
282
  if (chain.outputKeys.length !== 1) {
@@ -271,7 +271,8 @@ export class SimpleSequentialChain extends BaseChain {
271
271
  /** @ignore */
272
272
  _validateChains() {
273
273
  for (const chain of this.chains) {
274
- if (chain.inputKeys.filter((k) => !chain.memory?.memoryKeys.includes(k) ?? true).length !== 1) {
274
+ if (chain.inputKeys.filter((k) => !chain.memory?.memoryKeys.includes(k))
275
+ .length !== 1) {
275
276
  throw new Error(`Chains used in SimpleSequentialChain should all have one input, got ${chain.inputKeys.length} for ${chain._chainType()}.`);
276
277
  }
277
278
  if (chain.outputKeys.length !== 1) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSqlQueryChain = exports.SqlDatabaseChain = void 0;
3
+ exports.SqlDatabaseChain = void 0;
4
+ exports.createSqlQueryChain = createSqlQueryChain;
4
5
  const base_1 = require("@langchain/core/language_models/base");
5
6
  const runnables_1 = require("@langchain/core/runnables");
6
7
  const output_parsers_1 = require("@langchain/core/output_parsers");
@@ -267,4 +268,3 @@ async function createSqlQueryChain({ llm, db, prompt, k = 5, dialect, }) {
267
268
  strip,
268
269
  ]);
269
270
  }
270
- exports.createSqlQueryChain = createSqlQueryChain;