Skip to content

Commit 1e8faaf

Browse files
committed
WIP: feat: add google vertex support
1 parent f375867 commit 1e8faaf

4 files changed

Lines changed: 63 additions & 5 deletions

File tree

google/google.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@ type provider struct {
2424
}
2525

2626
type options struct {
27-
apiKey string
28-
name string
29-
headers map[string]string
30-
client *http.Client
27+
apiKey string
28+
name string
29+
headers map[string]string
30+
client *http.Client
31+
backend genai.Backend
32+
project string
33+
location string
3134
}
3235

3336
type Option = func(*options)
3437

3538
func New(opts ...Option) ai.Provider {
3639
options := options{
3740
headers: map[string]string{},
41+
backend: genai.BackendGeminiAPI,
3842
}
3943
for _, o := range opts {
4044
o(&options)
@@ -71,6 +75,14 @@ func WithHTTPClient(client *http.Client) Option {
7175
}
7276
}
7377

78+
func WithVertex(project, location string) Option {
79+
return func(o *options) {
80+
o.backend = genai.BackendVertexAI
81+
o.project = project
82+
o.location = location
83+
}
84+
}
85+
7486
func (*provider) Name() string {
7587
return Name
7688
}
@@ -94,8 +106,10 @@ type languageModel struct {
94106
func (g *provider) LanguageModel(modelID string) (ai.LanguageModel, error) {
95107
cc := &genai.ClientConfig{
96108
APIKey: g.options.apiKey,
97-
Backend: genai.BackendGeminiAPI,
98109
HTTPClient: g.options.client,
110+
Backend: g.options.backend,
111+
Project: g.options.project,
112+
Location: g.options.location,
99113
}
100114
client, err := genai.NewClient(context.Background(), cc)
101115
if err != nil {

providertests/.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
ANTHROPIC_API_KEY=
22
GEMINI_API_KEY=
33
OPENAI_API_KEY=
4+
VERTEX_API_KEY=
5+
VERTEX_PROJECT=
6+
VERTEX_LOCATION=us-central1

providertests/builders_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var languageModelBuilders = []builderPair{
2525
{"anthropic-claude-sonnet", builderAnthropicClaudeSonnet4},
2626
{"google-gemini-2.5-flash", builderGoogleGemini25Flash},
2727
{"google-gemini-2.5-pro", builderGoogleGemini25Pro},
28+
{"google-vertex-claude-sonnet", buildVertexClaudeSonnet},
2829
}
2930

3031
var thinkingLanguageModelBuilders = []builderPair{
@@ -80,3 +81,12 @@ func builderGoogleGemini25Pro(r *recorder.Recorder) (ai.LanguageModel, error) {
8081
)
8182
return provider.LanguageModel("gemini-2.5-pro")
8283
}
84+
85+
func buildVertexClaudeSonnet(r *recorder.Recorder) (ai.LanguageModel, error) {
86+
provider := google.New(
87+
google.WithAPIKey(cmp.Or(os.Getenv("VERTEX_API_KEY"), "(missing)")),
88+
google.WithVertex(os.Getenv("VERTEX_PROJECT"), os.Getenv("VERTEX_LOCATION")),
89+
google.WithHTTPClient(&http.Client{Transport: r}),
90+
)
91+
return provider.LanguageModel("claude-3-7-sonnet@20250219")
92+
}

providertests/testdata/TestSimple/google-vertex-claude-sonnet.yaml

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)