Skip to content

Commit

Permalink
chore(adapters): add VertexAI examples
Browse files Browse the repository at this point in the history
Ref: #141
Signed-off-by: Tomas Dvorak <[email protected]>
  • Loading branch information
Tomas2D committed Nov 26, 2024
1 parent b5e10fa commit a06ef6f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions examples/llms/providers/vertexai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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());
}
1 change: 1 addition & 0 deletions tests/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const exclude: string[] = [
["examples/llms/providers/bam.ts", "examples/llms/providers/bam_verbose.ts"],
!hasEnv("ELASTICSEARCH_NODE") && ["examples/agents/elasticsearch.ts"],
!hasEnv("AWS_REGION") && ["examples/llms/providers/bedrock.ts"],
!hasEnv("GOOGLE_APPLICATION_CREDENTIALS") && ["examples/llms/providers/vertexai.ts"],
]
.filter(isTruthy)
.flat(); // list of examples that are excluded
Expand Down

0 comments on commit a06ef6f

Please sign in to comment.