-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenai_chat_tool_trace.mjs
More file actions
67 lines (62 loc) · 1.53 KB
/
Copy pathopenai_chat_tool_trace.mjs
File metadata and controls
67 lines (62 loc) · 1.53 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import "dotenv/config";
import OpenAI from "openai";
import { traceable } from "langsmith/traceable";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const model = process.env.OPENAI_MODEL || "gpt-5.5";
const invokeChatTool = traceable(
async () =>
client.chat.completions.create({
model,
messages: [
{
role: "user",
content:
"Call lookup_trace_contract with query 'langsmith trace depth'. Do not answer directly.",
},
],
tool_choice: "required",
parallel_tool_calls: false,
tools: [
{
type: "function",
function: {
name: "lookup_trace_contract",
description: "Look up trace contract details.",
parameters: {
type: "object",
additionalProperties: false,
required: ["query"],
properties: {
query: { type: "string" },
},
},
},
},
],
}),
{
name: "openai_chat_tool_trace",
run_type: "llm",
metadata: {
scenario: "openai-sdk-chat-tool",
},
}
);
const response = await invokeChatTool();
console.log(
JSON.stringify(
{
object: response.object,
finish_reason: response.choices?.[0]?.finish_reason,
tool_calls: response.choices?.[0]?.message?.tool_calls?.map((call) => ({
type: call.type,
name: call.function?.name,
})),
usage_present: Boolean(response.usage),
},
null,
2
)
);