langchain 0.2.7 → 0.2.8

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderTextDescriptionAndArgs = exports.renderTextDescription = void 0;
4
4
  const zod_to_json_schema_1 = require("zod-to-json-schema");
5
+ const base_1 = require("@langchain/core/language_models/base");
5
6
  /**
6
7
  * Render the tool name and description in plain text.
7
8
  *
@@ -14,7 +15,14 @@ const zod_to_json_schema_1 = require("zod-to-json-schema");
14
15
  * @returns a string of all tools and their descriptions
15
16
  */
16
17
  function renderTextDescription(tools) {
17
- return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
18
+ if (tools.every(base_1.isOpenAITool)) {
19
+ return tools
20
+ .map((tool) => `${tool.function.name}${tool.function.description ? `: ${tool.function.description}` : ""}`)
21
+ .join("\n");
22
+ }
23
+ return tools
24
+ .map((tool) => `${tool.name}: ${tool.description}`)
25
+ .join("\n");
18
26
  }
19
27
  exports.renderTextDescription = renderTextDescription;
20
28
  /**
@@ -29,6 +37,11 @@ exports.renderTextDescription = renderTextDescription;
29
37
  * @returns a string of all tools, their descriptions and a stringified version of their schemas
30
38
  */
31
39
  function renderTextDescriptionAndArgs(tools) {
40
+ if (tools.every(base_1.isOpenAITool)) {
41
+ return tools
42
+ .map((tool) => `${tool.function.name}${tool.function.description ? `: ${tool.function.description}` : ""}, args: ${JSON.stringify(tool.function.parameters)}`)
43
+ .join("\n");
44
+ }
32
45
  return tools
33
46
  .map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify((0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema).properties)}`)
34
47
  .join("\n");
@@ -1,4 +1,5 @@
1
1
  import { StructuredToolInterface } from "@langchain/core/tools";
2
+ import { ToolDefinition } from "@langchain/core/language_models/base";
2
3
  /**
3
4
  * Render the tool name and description in plain text.
4
5
  *
@@ -10,7 +11,7 @@ import { StructuredToolInterface } from "@langchain/core/tools";
10
11
  * @param tools
11
12
  * @returns a string of all tools and their descriptions
12
13
  */
13
- export declare function renderTextDescription(tools: StructuredToolInterface[]): string;
14
+ export declare function renderTextDescription(tools: StructuredToolInterface[] | ToolDefinition[]): string;
14
15
  /**
15
16
  * Render the tool name, description, and args in plain text.
16
17
  * Output will be in the format of:'
@@ -22,4 +23,4 @@ export declare function renderTextDescription(tools: StructuredToolInterface[]):
22
23
  * @param tools
23
24
  * @returns a string of all tools, their descriptions and a stringified version of their schemas
24
25
  */
25
- export declare function renderTextDescriptionAndArgs(tools: StructuredToolInterface[]): string;
26
+ export declare function renderTextDescriptionAndArgs(tools: StructuredToolInterface[] | ToolDefinition[]): string;
@@ -1,4 +1,5 @@
1
1
  import { zodToJsonSchema } from "zod-to-json-schema";
2
+ import { isOpenAITool, } from "@langchain/core/language_models/base";
2
3
  /**
3
4
  * Render the tool name and description in plain text.
4
5
  *
@@ -11,7 +12,14 @@ import { zodToJsonSchema } from "zod-to-json-schema";
11
12
  * @returns a string of all tools and their descriptions
12
13
  */
13
14
  export function renderTextDescription(tools) {
14
- return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
15
+ if (tools.every(isOpenAITool)) {
16
+ return tools
17
+ .map((tool) => `${tool.function.name}${tool.function.description ? `: ${tool.function.description}` : ""}`)
18
+ .join("\n");
19
+ }
20
+ return tools
21
+ .map((tool) => `${tool.name}: ${tool.description}`)
22
+ .join("\n");
15
23
  }
16
24
  /**
17
25
  * Render the tool name, description, and args in plain text.
@@ -25,6 +33,11 @@ export function renderTextDescription(tools) {
25
33
  * @returns a string of all tools, their descriptions and a stringified version of their schemas
26
34
  */
27
35
  export function renderTextDescriptionAndArgs(tools) {
36
+ if (tools.every(isOpenAITool)) {
37
+ return tools
38
+ .map((tool) => `${tool.function.name}${tool.function.description ? `: ${tool.function.description}` : ""}, args: ${JSON.stringify(tool.function.parameters)}`)
39
+ .join("\n");
40
+ }
28
41
  return tools
29
42
  .map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify(zodToJsonSchema(tool.schema).properties)}`)
30
43
  .join("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -888,7 +888,7 @@
888
888
  }
889
889
  },
890
890
  "dependencies": {
891
- "@langchain/core": "~0.2.0",
891
+ "@langchain/core": ">=0.2.9 <0.3.0",
892
892
  "@langchain/openai": ">=0.1.0 <0.3.0",
893
893
  "@langchain/textsplitters": "~0.0.0",
894
894
  "binary-extensions": "^2.2.0",