-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
chat_convo_with_tracing.ts
45 lines (34 loc) 路 1.44 KB
/
chat_convo_with_tracing.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
44
45
import { ChatOpenAI } from "@langchain/openai";
import { initializeAgentExecutorWithOptions } from "langchain/agents";
import { Calculator } from "@langchain/community/tools/calculator";
import { SerpAPI } from "@langchain/community/tools/serpapi";
export const run = async () => {
process.env.LANGCHAIN_HANDLER = "langchain";
const model = new ChatOpenAI({ temperature: 0 });
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
// Passing "chat-conversational-react-description" as the agent type
// automatically creates and uses BufferMemory with the executor.
// If you would like to override this, you can pass in a custom
// memory option, but the memoryKey set on it must be "chat_history".
const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "chat-conversational-react-description",
verbose: true,
});
console.log("Loaded agent.");
const input0 = "hi, i am bob";
const result0 = await executor.invoke({ input: input0 });
console.log(`Got output ${result0.output}`);
const input1 = "whats my name?";
const result1 = await executor.invoke({ input: input1 });
console.log(`Got output ${result1.output}`);
const input2 = "whats the weather in pomfret?";
const result2 = await executor.invoke({ input: input2 });
console.log(`Got output ${result2.output}`);
};