Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions llms/googleai/googleai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,35 @@ func TestGoogleAIGenerateContentWithSystemMessage(t *testing.T) {
assert.NotEmpty(t, resp.Choices)
}

func TestGoogleAIGenerateContentWithCustomBaseURL(t *testing.T) {
// This proves the option is accepted and doesn't break the SDK's path construction.
officialBaseURL := "https://generativelanguage.googleapis.com"

llm := newHTTPRRClient(t, WithBaseURL(officialBaseURL))

ctx := context.Background()
content := []llms.MessageContent{
{
Role: llms.ChatMessageTypeHuman,
Parts: []llms.ContentPart{
llms.TextPart("Hey! How are you doing?"),
},
},
}

resp, err := llm.GenerateContent(ctx, content)
if err != nil {
// Check if this is a recording mismatch error
if strings.Contains(err.Error(), "cached HTTP response not found") {
t.Skip("Recording format has changed or is incompatible. Hint: Re-run tests with -httprecord=. to record new HTTP interactions")
}
require.NoError(t, err)
}

require.NoError(t, err)
require.NotNil(t, resp)
}

func TestGoogleAICall(t *testing.T) {

llm := newHTTPRRClient(t)
Expand Down
6 changes: 6 additions & 0 deletions llms/googleai/googleai_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ func TestOptions(t *testing.T) { //nolint:funlen // comprehensive test //nolint:
assert.Len(t, opts.ClientOptions, 1)
})

t.Run("WithBaseURL", func(t *testing.T) {
opts := &Options{}
WithBaseURL("https://custom.endpoint.com")(opts)
assert.Len(t, opts.ClientOptions, 1)
})

t.Run("WithHTTPClient", func(t *testing.T) {
opts := &Options{}
WithHTTPClient(nil)(opts)
Expand Down
10 changes: 10 additions & 0 deletions llms/googleai/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ func WithRest() Option {
}
}

// WithBaseURL appends a ClientOption that configures the underlying Google AI
// client to use a custom base URL (endpoint). This is useful for directing
// requests to proxy servers, local development environments, or alternative
// regional endpoints not automatically handled by the default client setup.
func WithBaseURL(baseURL string) Option {
return func(opts *Options) {
opts.ClientOptions = append(opts.ClientOptions, option.WithEndpoint(baseURL))
}
}

// WithHTTPClient append a ClientOption that uses the provided HTTP client to
// make requests.
// This is useful for vertex clients.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading