langchain 0.3.19 → 0.3.21

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.
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStructuredChatAgent = exports.StructuredChatAgent = void 0;
4
- const zod_to_json_schema_1 = require("zod-to-json-schema");
5
4
  const base_1 = require("@langchain/core/language_models/base");
6
5
  const runnables_1 = require("@langchain/core/runnables");
7
6
  const prompts_1 = require("@langchain/core/prompts");
8
7
  const function_calling_1 = require("@langchain/core/utils/function_calling");
8
+ const zod_to_json_schema_1 = require("zod-to-json-schema");
9
+ const types_1 = require("@langchain/core/utils/types");
9
10
  const llm_chain_js_1 = require("../../chains/llm_chain.cjs");
10
11
  const agent_js_1 = require("../agent.cjs");
11
12
  const outputParser_js_1 = require("./outputParser.cjs");
@@ -93,7 +94,10 @@ class StructuredChatAgent extends agent_js_1.Agent {
93
94
  */
94
95
  static createToolSchemasString(tools) {
95
96
  return tools
96
- .map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify((0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema).properties)}`)
97
+ .map((tool) => {
98
+ const jsonSchema = ((0, types_1.isZodSchema)(tool.schema) ? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema) : tool.schema);
99
+ return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
100
+ })
97
101
  .join("\n");
98
102
  }
99
103
  /**
@@ -1,8 +1,9 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
1
  import { isOpenAITool, } from "@langchain/core/language_models/base";
3
2
  import { RunnablePassthrough } from "@langchain/core/runnables";
4
3
  import { ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate, PromptTemplate, } from "@langchain/core/prompts";
5
4
  import { isStructuredTool } from "@langchain/core/utils/function_calling";
5
+ import { zodToJsonSchema } from "zod-to-json-schema";
6
+ import { isZodSchema } from "@langchain/core/utils/types";
6
7
  import { LLMChain } from "../../chains/llm_chain.js";
7
8
  import { Agent, AgentRunnableSequence, } from "../agent.js";
8
9
  import { StructuredChatOutputParserWithRetries } from "./outputParser.js";
@@ -90,7 +91,10 @@ export class StructuredChatAgent extends Agent {
90
91
  */
91
92
  static createToolSchemasString(tools) {
92
93
  return tools
93
- .map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify(zodToJsonSchema(tool.schema).properties)}`)
94
+ .map((tool) => {
95
+ const jsonSchema = (isZodSchema(tool.schema) ? zodToJsonSchema(tool.schema) : tool.schema);
96
+ return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
97
+ })
94
98
  .join("\n");
95
99
  }
96
100
  /**
@@ -8,4 +8,8 @@ export declare function createRetrieverTool(retriever: BaseRetrieverInterface, i
8
8
  input: string;
9
9
  }, {
10
10
  input: string;
11
- }>>;
11
+ }>, {
12
+ input: string;
13
+ }, {
14
+ input: string;
15
+ }>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStructuredOutputRunnable = exports.createOpenAIFnRunnable = void 0;
4
+ const types_1 = require("@langchain/core/utils/types");
4
5
  const zod_to_json_schema_1 = require("zod-to-json-schema");
5
6
  const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
6
7
  /**
@@ -67,9 +68,6 @@ function createOpenAIFnRunnable(config) {
67
68
  return prompt.pipe(llmWithKwargs).pipe(outputParser);
68
69
  }
69
70
  exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
70
- function isZodSchema(schema) {
71
- return typeof schema.safeParse === "function";
72
- }
73
71
  /**
74
72
  * @deprecated Prefer the `.withStructuredOutput` method on chat model classes.
75
73
  *
@@ -127,7 +125,7 @@ function isZodSchema(schema) {
127
125
  */
128
126
  function createStructuredOutputRunnable(config) {
129
127
  const { outputSchema, llm, prompt, outputParser } = config;
130
- const jsonSchema = isZodSchema(outputSchema)
128
+ const jsonSchema = (0, types_1.isZodSchema)(outputSchema)
131
129
  ? (0, zod_to_json_schema_1.zodToJsonSchema)(outputSchema)
132
130
  : outputSchema;
133
131
  const oaiFunction = {
@@ -1,11 +1,11 @@
1
1
  import type { z } from "zod";
2
- import { JsonSchema7Type } from "zod-to-json-schema";
3
2
  import type { BaseOutputParser } from "@langchain/core/output_parsers";
4
3
  import type { BasePromptTemplate } from "@langchain/core/prompts";
5
4
  import type { Runnable, RunnableInterface } from "@langchain/core/runnables";
6
5
  import type { BaseFunctionCallOptions, BaseLanguageModelInput, FunctionDefinition } from "@langchain/core/language_models/base";
7
- import type { InputValues } from "@langchain/core/utils/types";
6
+ import { type InputValues } from "@langchain/core/utils/types";
8
7
  import type { BaseMessage } from "@langchain/core/messages";
8
+ import { type JsonSchema7Type } from "zod-to-json-schema";
9
9
  /**
10
10
  * Configuration params for the createOpenAIFnRunnable method.
11
11
  */
@@ -1,3 +1,4 @@
1
+ import { isZodSchema } from "@langchain/core/utils/types";
1
2
  import { zodToJsonSchema } from "zod-to-json-schema";
2
3
  import { JsonOutputFunctionsParser } from "../../output_parsers/openai_functions.js";
3
4
  /**
@@ -63,9 +64,6 @@ export function createOpenAIFnRunnable(config) {
63
64
  const llmWithKwargs = llm.bind(llmKwargs);
64
65
  return prompt.pipe(llmWithKwargs).pipe(outputParser);
65
66
  }
66
- function isZodSchema(schema) {
67
- return typeof schema.safeParse === "function";
68
- }
69
67
  /**
70
68
  * @deprecated Prefer the `.withStructuredOutput` method on chat model classes.
71
69
  *
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPrompt = exports.PromptGenerator = void 0;
4
+ const types_1 = require("@langchain/core/utils/types");
4
5
  const zod_to_json_schema_1 = require("zod-to-json-schema");
5
6
  const schema_js_1 = require("./schema.cjs");
6
7
  /**
@@ -72,7 +73,8 @@ class PromptGenerator {
72
73
  }
73
74
  _generate_command_string(tool) {
74
75
  let output = `"${tool.name}": ${tool.description}`;
75
- output += `, args json schema: ${JSON.stringify((0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema).properties)}`;
76
+ const jsonSchema = ((0, types_1.isZodSchema)(tool.schema) ? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema) : tool.schema);
77
+ output += `, args json schema: ${JSON.stringify(jsonSchema?.properties)}`;
76
78
  return output;
77
79
  }
78
80
  /**
@@ -1,3 +1,4 @@
1
+ import { isZodSchema } from "@langchain/core/utils/types";
1
2
  import { zodToJsonSchema } from "zod-to-json-schema";
2
3
  import { FINISH_NAME } from "./schema.js";
3
4
  /**
@@ -69,7 +70,8 @@ export class PromptGenerator {
69
70
  }
70
71
  _generate_command_string(tool) {
71
72
  let output = `"${tool.name}": ${tool.description}`;
72
- output += `, args json schema: ${JSON.stringify(zodToJsonSchema(tool.schema).properties)}`;
73
+ const jsonSchema = (isZodSchema(tool.schema) ? zodToJsonSchema(tool.schema) : tool.schema);
74
+ output += `, args json schema: ${JSON.stringify(jsonSchema?.properties)}`;
73
75
  return output;
74
76
  }
75
77
  /**
@@ -1,10 +1,10 @@
1
- import { StructuredTool } from "@langchain/core/tools";
1
+ import { StructuredTool, ToolInterface } from "@langchain/core/tools";
2
2
  /**
3
3
  * Type alias for StructuredTool. It is part of the tools module in
4
4
  * LangChain, which includes a variety of tools used for different
5
5
  * purposes.
6
6
  */
7
- export type ObjectTool = StructuredTool;
7
+ export type ObjectTool = StructuredTool | ToolInterface;
8
8
  export declare const FINISH_NAME = "finish";
9
9
  /**
10
10
  * Interface that describes an action that can be performed by the AutoGPT
package/dist/hub/base.cjs CHANGED
@@ -74,7 +74,10 @@ modelClass) {
74
74
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
75
  const modelLcName = modelClass?.lc_name();
76
76
  let importMapKey;
77
- if (modelLcName === "ChatAnthropic") {
77
+ if (modelLcName === "ChatOpenAI") {
78
+ importMapKey = "chat_models__openai";
79
+ }
80
+ else if (modelLcName === "ChatAnthropic") {
78
81
  importMapKey = "chat_models__anthropic";
79
82
  }
80
83
  else if (modelLcName === "ChatAzureOpenAI") {
@@ -99,7 +102,7 @@ modelClass) {
99
102
  importMapKey = "chat_models__groq";
100
103
  }
101
104
  else {
102
- throw new Error("Received unsupport model class when pulling prompt.");
105
+ throw new Error("Received unsupported model class when pulling prompt.");
103
106
  }
104
107
  modelImportMap[importMapKey] = {
105
108
  ...modelImportMap[importMapKey],
package/dist/hub/base.js CHANGED
@@ -69,7 +69,10 @@ modelClass) {
69
69
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
70
  const modelLcName = modelClass?.lc_name();
71
71
  let importMapKey;
72
- if (modelLcName === "ChatAnthropic") {
72
+ if (modelLcName === "ChatOpenAI") {
73
+ importMapKey = "chat_models__openai";
74
+ }
75
+ else if (modelLcName === "ChatAnthropic") {
73
76
  importMapKey = "chat_models__anthropic";
74
77
  }
75
78
  else if (modelLcName === "ChatAzureOpenAI") {
@@ -94,7 +97,7 @@ modelClass) {
94
97
  importMapKey = "chat_models__groq";
95
98
  }
96
99
  else {
97
- throw new Error("Received unsupport model class when pulling prompt.");
100
+ throw new Error("Received unsupported model class when pulling prompt.");
98
101
  }
99
102
  modelImportMap[importMapKey] = {
100
103
  ...modelImportMap[importMapKey],
package/dist/hub/node.cjs CHANGED
@@ -20,7 +20,10 @@ async function pull(ownerRepoCommit, options) {
20
20
  if (options?.includeModel) {
21
21
  if (Array.isArray(promptObject.manifest.kwargs?.last?.kwargs?.bound?.id)) {
22
22
  const modelName = promptObject.manifest.kwargs?.last?.kwargs?.bound?.id.at(-1);
23
- if (modelName === "ChatAnthropic") {
23
+ if (modelName === "ChatOpenAI") {
24
+ modelClass = (await import("@langchain/openai")).ChatOpenAI;
25
+ }
26
+ else if (modelName === "ChatAnthropic") {
24
27
  modelClass = (await import("@langchain/anthropic")).ChatAnthropic;
25
28
  }
26
29
  else if (modelName === "ChatAzureOpenAI") {
package/dist/hub/node.js CHANGED
@@ -18,7 +18,10 @@ export async function pull(ownerRepoCommit, options) {
18
18
  if (options?.includeModel) {
19
19
  if (Array.isArray(promptObject.manifest.kwargs?.last?.kwargs?.bound?.id)) {
20
20
  const modelName = promptObject.manifest.kwargs?.last?.kwargs?.bound?.id.at(-1);
21
- if (modelName === "ChatAnthropic") {
21
+ if (modelName === "ChatOpenAI") {
22
+ modelClass = (await import("@langchain/openai")).ChatOpenAI;
23
+ }
24
+ else if (modelName === "ChatAnthropic") {
22
25
  modelClass = (await import("@langchain/anthropic")).ChatAnthropic;
23
26
  }
24
27
  else if (modelName === "ChatAzureOpenAI") {
@@ -1,17 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatToOpenAIAssistantTool = exports.formatToOpenAITool = exports.formatToOpenAIFunction = void 0;
4
- const zod_to_json_schema_1 = require("zod-to-json-schema");
5
4
  const function_calling_1 = require("@langchain/core/utils/function_calling");
6
5
  Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return function_calling_1.convertToOpenAIFunction; } });
7
6
  Object.defineProperty(exports, "formatToOpenAITool", { enumerable: true, get: function () { return function_calling_1.convertToOpenAITool; } });
7
+ const types_1 = require("@langchain/core/utils/types");
8
+ const zod_to_json_schema_1 = require("zod-to-json-schema");
8
9
  function formatToOpenAIAssistantTool(tool) {
9
10
  return {
10
11
  type: "function",
11
12
  function: {
12
13
  name: tool.name,
13
14
  description: tool.description,
14
- parameters: (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema),
15
+ parameters: (0, types_1.isZodSchema)(tool.schema)
16
+ ? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema)
17
+ : tool.schema,
15
18
  },
16
19
  };
17
20
  }
@@ -1,16 +1,5 @@
1
+ import { ToolDefinition } from "@langchain/core/language_models/base";
1
2
  import type { StructuredToolInterface } from "@langchain/core/tools";
2
3
  import { convertToOpenAIFunction, convertToOpenAITool } from "@langchain/core/utils/function_calling";
3
4
  export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
4
- export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): {
5
- type: string;
6
- function: {
7
- name: string;
8
- description: string;
9
- parameters: import("zod-to-json-schema").JsonSchema7Type & {
10
- $schema?: string | undefined;
11
- definitions?: {
12
- [key: string]: import("zod-to-json-schema").JsonSchema7Type;
13
- } | undefined;
14
- };
15
- };
16
- };
5
+ export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): ToolDefinition;
@@ -1,5 +1,6 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
1
  import { convertToOpenAIFunction, convertToOpenAITool, } from "@langchain/core/utils/function_calling";
2
+ import { isZodSchema } from "@langchain/core/utils/types";
3
+ import { zodToJsonSchema } from "zod-to-json-schema";
3
4
  export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
4
5
  export function formatToOpenAIAssistantTool(tool) {
5
6
  return {
@@ -7,7 +8,9 @@ export function formatToOpenAIAssistantTool(tool) {
7
8
  function: {
8
9
  name: tool.name,
9
10
  description: tool.description,
10
- parameters: zodToJsonSchema(tool.schema),
11
+ parameters: isZodSchema(tool.schema)
12
+ ? zodToJsonSchema(tool.schema)
13
+ : tool.schema,
11
14
  },
12
15
  };
13
16
  }
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderTextDescriptionAndArgs = exports.renderTextDescription = void 0;
4
- const zod_to_json_schema_1 = require("zod-to-json-schema");
5
4
  const base_1 = require("@langchain/core/language_models/base");
5
+ const zod_to_json_schema_1 = require("zod-to-json-schema");
6
+ const types_1 = require("@langchain/core/utils/types");
6
7
  /**
7
8
  * Render the tool name and description in plain text.
8
9
  *
@@ -43,7 +44,10 @@ function renderTextDescriptionAndArgs(tools) {
43
44
  .join("\n");
44
45
  }
45
46
  return tools
46
- .map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify((0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema).properties)}`)
47
+ .map((tool) => {
48
+ const jsonSchema = ((0, types_1.isZodSchema)(tool.schema) ? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema) : tool.schema);
49
+ return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
50
+ })
47
51
  .join("\n");
48
52
  }
49
53
  exports.renderTextDescriptionAndArgs = renderTextDescriptionAndArgs;
@@ -1,5 +1,6 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
1
  import { isOpenAITool, } from "@langchain/core/language_models/base";
2
+ import { zodToJsonSchema } from "zod-to-json-schema";
3
+ import { isZodSchema } from "@langchain/core/utils/types";
3
4
  /**
4
5
  * Render the tool name and description in plain text.
5
6
  *
@@ -39,6 +40,9 @@ export function renderTextDescriptionAndArgs(tools) {
39
40
  .join("\n");
40
41
  }
41
42
  return tools
42
- .map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify(zodToJsonSchema(tool.schema).properties)}`)
43
+ .map((tool) => {
44
+ const jsonSchema = (isZodSchema(tool.schema) ? zodToJsonSchema(tool.schema) : tool.schema);
45
+ return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
46
+ })
43
47
  .join("\n");
44
48
  }
@@ -7,4 +7,8 @@ export declare function createRetrieverTool(retriever: BaseRetrieverInterface, i
7
7
  query: string;
8
8
  }, {
9
9
  query: string;
10
- }>>;
10
+ }>, {
11
+ query: string;
12
+ }, {
13
+ query: string;
14
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -457,6 +457,7 @@
457
457
  "openai": "^4.41.1",
458
458
  "peggy": "^3.0.2",
459
459
  "prettier": "^2.8.3",
460
+ "reflect-metadata": "^0.2.2",
460
461
  "release-it": "^17.6.0",
461
462
  "rimraf": "^5.0.1",
462
463
  "rollup": "^3.19.1",
@@ -539,7 +540,7 @@
539
540
  }
540
541
  },
541
542
  "dependencies": {
542
- "@langchain/openai": ">=0.1.0 <0.5.0",
543
+ "@langchain/openai": ">=0.1.0 <0.6.0",
543
544
  "@langchain/textsplitters": ">=0.0.0 <0.2.0",
544
545
  "js-tiktoken": "^1.0.12",
545
546
  "js-yaml": "^4.1.0",