-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlangchain_chatopenai_tool_trace.mjs
More file actions
45 lines (41 loc) · 1.03 KB
/
Copy pathlangchain_chatopenai_tool_trace.mjs
File metadata and controls
45 lines (41 loc) · 1.03 KB
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
44
45
import "dotenv/config";
import { ChatOpenAI } from "@langchain/openai";
import { tool } from "@langchain/core/tools";
import { z } from "zod";
const lookupTraceContract = tool(
async ({ query }) => `trace contract lookup: ${query}`,
{
name: "lookup_trace_contract",
description: "Look up trace contract details.",
schema: z.object({
query: z.string(),
}),
}
);
const model = new ChatOpenAI({
model: process.env.OPENAI_MODEL || "gpt-5.5",
apiKey: process.env.OPENAI_API_KEY,
}).bindTools([lookupTraceContract], {
tool_choice: "lookup_trace_contract",
});
const result = await model.invoke(
"Call lookup_trace_contract with query 'langsmith trace depth'."
);
console.log(
JSON.stringify(
{
content: result.content,
tool_calls: result.tool_calls?.map((call) => ({
name: call.name,
args_shape: Object.fromEntries(
Object.entries(call.args ?? {}).map(([key, value]) => [
key,
typeof value,
])
),
})),
},
null,
2
)
);