Skip to content

Commit a29b806

Browse files
yinghsienwucopybara-github
authored andcommitted
feat: Support global endpoint in go natively
PiperOrigin-RevId: 738046161
1 parent c33398a commit a29b806

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ func NewClient(ctx context.Context, cc *ClientConfig) (*Client, error) {
137137
}
138138

139139
if cc.HTTPOptions.BaseURL == "" && cc.Backend == BackendVertexAI {
140-
cc.HTTPOptions.BaseURL = fmt.Sprintf("https://%s-aiplatform.googleapis.com/", cc.Location)
140+
if cc.Location == "global" {
141+
cc.HTTPOptions.BaseURL = "https://aiplatform.googleapis.com/"
142+
} else {
143+
cc.HTTPOptions.BaseURL = fmt.Sprintf("https://%s-aiplatform.googleapis.com/", cc.Location)
144+
}
141145
} else if cc.HTTPOptions.BaseURL == "" {
142146
cc.HTTPOptions.BaseURL = "https://generativelanguage.googleapis.com/"
143147
}

client_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,18 @@ func TestClientConfigHTTPOptions(t *testing.T) {
404404
expectedBaseURL: "https://us-central1-aiplatform.googleapis.com/",
405405
expectedAPIVersion: "v1beta1",
406406
},
407+
{
408+
name: "Vertex AI Backend with global location",
409+
clientConfig: ClientConfig{
410+
Backend: BackendVertexAI,
411+
Project: "test-project",
412+
Location: "global",
413+
HTTPOptions: HTTPOptions{},
414+
Credentials: &google.Credentials{},
415+
},
416+
expectedBaseURL: "https://aiplatform.googleapis.com/",
417+
expectedAPIVersion: "v1beta1",
418+
},
407419
{
408420
name: "Google AI Backend with HTTP Client Timeout and no HTTPOptions",
409421
clientConfig: ClientConfig{

0 commit comments

Comments
 (0)