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
import process from "node:process";
export const chatAgentWithCustomPrompt = (async () => {
const { ChatOpenAI } = await import(
"https://esm.sh/langchain/chat_models/openai"
);
const { initializeAgentExecutorWithOptions } = await import(
"https://esm.sh/langchain/agents"
);
const { Calculator } = await import(
"https://esm.sh/langchain/tools/calculator"
);
const model = new ChatOpenAI({
temperature: 0,
openAIApiKey: process.env.OPENAI_API_KEY,
});
const tools = [
new Calculator(),
];
const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "chat-zero-shot-react-description",
verbose: true,
agentArgs: {
humanMessageTemplate:
"{input}\n\n{agent_scratchpad}\nYou must also always give your final answer in French, as the human you are talking to only speaks French.",
},
});
const result = await executor.call({
input: `How is your day going?`,
});
// You could also just translate the English output of the agent into French with another LLM call
return result;
})();
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.