-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
render.ts
43 lines (41 loc) · 1.26 KB
/
render.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { zodToJsonSchema, JsonSchema7ObjectType } from "zod-to-json-schema";
import { StructuredToolInterface } from "@langchain/core/tools";
/**
* Render the tool name and description in plain text.
*
* Output will be in the format of:
* ```
* search: This tool is used for search
* calculator: This tool is used for math
* ```
* @param tools
* @returns a string of all tools and their descriptions
*/
export function renderTextDescription(
tools: StructuredToolInterface[]
): string {
return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
}
/**
* Render the tool name, description, and args in plain text.
* Output will be in the format of:'
* ```
* search: This tool is used for search, args: {"query": {"type": "string"}}
* calculator: This tool is used for math,
* args: {"expression": {"type": "string"}}
* ```
* @param tools
* @returns a string of all tools, their descriptions and a stringified version of their schemas
*/
export function renderTextDescriptionAndArgs(
tools: StructuredToolInterface[]
): string {
return tools
.map(
(tool) =>
`${tool.name}: ${tool.description}, args: ${JSON.stringify(
(zodToJsonSchema(tool.schema) as JsonSchema7ObjectType).properties
)}`
)
.join("\n");
}