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
4 changes: 2 additions & 2 deletions api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,14 @@ func iterateResponseStream[R any](rs *responseStream[R], responseConverter func(

// APIError contains an error response from the server.
type APIError struct {
// Code is the HTTP response status code.
Code int `json:"code,omitempty"`
// Message is the server response message.
Message string `json:"message,omitempty"`
// Status is the server response status.
Status string `json:"status,omitempty"`
// Details field provides more context to an error.
Details []map[string]any `json:"details,omitempty"`
// Code is the HTTP response status code.
Code int `json:"code,omitempty"`
}

type responseWithError struct {
Expand Down
42 changes: 21 additions & 21 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

// Client is the GenAI client. It provides access to the various GenAI services.
type Client struct {
clientConfig ClientConfig
// Models provides access to the Models service.
Models *Models
// Live provides access to the Live service.
Expand All @@ -47,7 +46,8 @@ type Client struct {
// Batches provides access to the Batch service.
Batches *Batches
// Tunings provides access to the Tunings service.
Tunings *Tunings
Tunings *Tunings
clientConfig ClientConfig
}

// Backend is the GenAI backend to use for the client.
Expand Down Expand Up @@ -80,15 +80,27 @@ func (t Backend) String() string {

// ClientConfig is the configuration for the GenAI client.
type ClientConfig struct {

// Optional HTTP options to override.
HTTPOptions HTTPOptions

// Optional. Google credentials. If not specified, [Application Default Credentials] will be used.
//
// [Application Default Credentials]: https://developers.google.com/accounts/docs/application-default-credentials
Credentials *auth.Credentials

// Optional HTTP client to use. If nil, a default client will be created.
// For Vertex AI, this client must handle authentication appropriately.
// Otherwise, call [UseDefaultCredentials] convenience method to add default credentials to the
// client.
HTTPClient *http.Client

envVarProvider func() map[string]string
// Optional. API Key for GenAI. Required for BackendGeminiAPI.
// Can also be set via the GOOGLE_API_KEY or GEMINI_API_KEY environment variable.
// Get a Gemini API key: https://ai.google.dev/gemini-api/docs/api-key
APIKey string

// Optional. Backend for GenAI. See Backend constants. Defaults to BackendGeminiAPI unless explicitly set to BackendVertexAI,
// or the environment variable GOOGLE_GENAI_USE_VERTEXAI is set to "1" or "true".
Backend Backend

// Optional. GCP Project ID for Vertex AI. Required for BackendVertexAI.
// Can also be set via the GOOGLE_CLOUD_PROJECT environment variable.
// Find your Project ID: https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects
Expand All @@ -99,21 +111,9 @@ type ClientConfig struct {
// Generative AI locations: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations.
Location string

// Optional. Google credentials. If not specified, [Application Default Credentials] will be used.
//
// [Application Default Credentials]: https://developers.google.com/accounts/docs/application-default-credentials
Credentials *auth.Credentials

// Optional HTTP client to use. If nil, a default client will be created.
// For Vertex AI, this client must handle authentication appropriately.
// Otherwise, call [UseDefaultCredentials] convenience method to add default credentials to the
// client.
HTTPClient *http.Client

// Optional HTTP options to override.
HTTPOptions HTTPOptions

envVarProvider func() map[string]string
// Optional. Backend for GenAI. See Backend constants. Defaults to BackendGeminiAPI unless explicitly set to BackendVertexAI,
// or the environment variable GOOGLE_GENAI_USE_VERTEXAI is set to "1" or "true".
Backend Backend
}

func defaultEnvVarProvider() map[string]string {
Expand Down
10 changes: 5 additions & 5 deletions pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ var ErrPageDone = errors.New("no more pages")
// Page represents a page of results from a paginated API call.
// It contains a slice of items and information about the next page.
type Page[T any] struct {
Name string // The name of the resource.
Items []*T // The items in the current page.
NextPageToken string // The token to use to retrieve the next page of results.
SDKHTTPResponse *HTTPResponse // The SDKHTTPResponse from the API call.

config map[string]any // The configuration used for the API call.
listFunc func(ctx context.Context, config map[string]any) ([]*T, string, *HTTPResponse, error) // The function used to retrieve the next page.
config map[string]any // The configuration used for the API call.
listFunc func(ctx context.Context, config map[string]any) ([]*T, string, *HTTPResponse, error) // The function used to retrieve the next page.
Name string // The name of the resource.
NextPageToken string // The token to use to retrieve the next page of results.
Items []*T // The items in the current page.
}

func newPage[T any](ctx context.Context, name string, config map[string]any, listFunc func(ctx context.Context, config map[string]any) ([]*T, string, *HTTPResponse, error)) (Page[T], error) {
Expand Down
4 changes: 2 additions & 2 deletions replay_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ import (
// ReplayAPIClient is a client that reads responses from a replay session file.
type replayAPIClient struct {
ReplayFile *replayFile
ReplaysDirectory string
currentInteractionIndex int
t *testing.T
server *httptest.Server
ReplaysDirectory string
currentInteractionIndex int
}

// NewReplayAPIClient creates a new ReplayAPIClient from a replay session file.
Expand Down