-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathintegration_googlevertexai-tools.ts
48 lines (44 loc) · 1.36 KB
/
integration_googlevertexai-tools.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
46
47
48
import { ChatVertexAI } from "@langchain/google-vertexai";
import { type GeminiTool } from "@langchain/google-vertexai/types";
import { zodToGeminiParameters } from "@langchain/google-vertexai/utils";
import { z } from "zod";
// Or, if using the web entrypoint:
// import { ChatVertexAI } from "@langchain/google-vertexai-web";
const calculatorSchema = z.object({
operation: z
.enum(["add", "subtract", "multiply", "divide"])
.describe("The type of operation to execute"),
number1: z.number().describe("The first number to operate on."),
number2: z.number().describe("The second number to operate on."),
});
const geminiCalculatorTool: GeminiTool = {
functionDeclarations: [
{
name: "calculator",
description: "A simple calculator tool",
parameters: zodToGeminiParameters(calculatorSchema),
},
],
};
const model = new ChatVertexAI({
temperature: 0.7,
model: "gemini-1.5-flash-001",
}).bind({
tools: [geminiCalculatorTool],
});
const response = await model.invoke("What is 1628253239 times 81623836?");
console.log(JSON.stringify(response.additional_kwargs, null, 2));
/*
{
"tool_calls": [
{
"id": "a20075d3b0e34f7ca60cc135916e620d",
"type": "function",
"function": {
"name": "calculator",
"arguments": "{\"number1\":1628253239,\"operation\":\"multiply\",\"number2\":81623836}"
}
}
]
}
*/