Skip to content

Commit ddd8a1a

Browse files
committed
Support full Google GenAI client options
1 parent 9ab5725 commit ddd8a1a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

.changeset/hot-crews-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Support full Google GenAI client options (to e.g. use Vertex AI, or control the region)

packages/core/lib/v3/llm/GoogleClient.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import {
88
FunctionCall,
99
Schema,
1010
Type,
11+
GoogleGenAIOptions as ClientOptions,
1112
} from "@google/genai";
1213

1314
import { LogLine } from "../types/public/logs";
14-
import { AvailableModel, ClientOptions } from "../types/public/model";
15+
import { AvailableModel } from "../types/public/model";
1516
import {
1617
validateZodSchema,
1718
toGeminiSchema,
@@ -71,15 +72,15 @@ export class GoogleClient extends LLMClient {
7172
}: {
7273
logger: (message: LogLine) => void; // Added logger type
7374
modelName: AvailableModel;
74-
clientOptions?: ClientOptions; // Expecting { apiKey: string } here
75+
clientOptions?: ClientOptions;
7576
}) {
7677
super(modelName);
7778
if (!clientOptions?.apiKey) {
7879
// Try to get the API key from the environment variable GOOGLE_API_KEY
7980
clientOptions.apiKey = loadApiKeyFromEnv("google_legacy", logger);
8081
}
8182
this.clientOptions = clientOptions;
82-
this.client = new GoogleGenAI({ apiKey: clientOptions.apiKey });
83+
this.client = new GoogleGenAI(clientOptions);
8384
this.modelName = modelName;
8485
this.logger = logger;
8586
// Determine vision capability based on model name (adjust as needed)

packages/core/lib/v3/types/public/model.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ClientOptions as AnthropicClientOptions } from "@anthropic-ai/sdk";
22
import type { LanguageModelV2 } from "@ai-sdk/provider";
3+
import { GoogleGenAIOptions as GoogleGenAIClientOptions } from "@google/genai";
34
import type { ClientOptions as OpenAIClientOptions } from "openai";
45

56
export type AnthropicJsonSchemaObject = {
@@ -66,7 +67,16 @@ export type ModelProvider =
6667
| "google"
6768
| "aisdk";
6869

69-
export type ClientOptions = OpenAIClientOptions | AnthropicClientOptions;
70+
export type ClientOptions = (
71+
| OpenAIClientOptions
72+
| AnthropicClientOptions
73+
| GoogleGenAIClientOptions
74+
) &
75+
// aisdk client language model options
76+
{
77+
apiKey?: string;
78+
baseURL?: string;
79+
};
7080

7181
export type ModelConfiguration =
7282
| AvailableModel

0 commit comments

Comments
 (0)