-
Notifications
You must be signed in to change notification settings - Fork 139
/
vertexai.ts
47 lines (39 loc) · 1.08 KB
/
vertexai.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
import "dotenv/config.js";
import { BaseMessage } from "bee-agent-framework/llms/primitives/message";
import { VertexAILLM } from "bee-agent-framework/adapters/vertexai/llm";
import { VertexAIChatLLM } from "bee-agent-framework/adapters/vertexai/chat";
const project = process.env.GCP_VERTEXAI_PROJECT;
const location = process.env.GCP_VERTEXAI_LOCATION;
if (!project || !location) {
throw new Error("No ENVs has been set!");
}
{
console.info("===RAW===");
const llm = new VertexAILLM({
modelId: "gemini-1.5-flash-001",
project,
location,
parameters: {},
});
console.info("Meta", await llm.meta());
const response = await llm.generate("Hello world!", {
stream: true,
});
console.info(response.getTextContent());
}
{
console.info("===CHAT===");
const llm = new VertexAIChatLLM({
modelId: "gemini-1.5-flash-001",
project,
location,
});
console.info("Meta", await llm.meta());
const response = await llm.generate([
BaseMessage.of({
role: "user",
text: "Hello world!",
}),
]);
console.info(response.getTextContent());
}