vertexai.go

 1package provider
 2
 3import (
 4	"context"
 5	"os"
 6
 7	"github.com/charmbracelet/crush/internal/logging"
 8	"google.golang.org/genai"
 9)
10
11type VertexAIClient ProviderClient
12
13func newVertexAIClient(opts providerClientOptions) VertexAIClient {
14	geminiOpts := geminiOptions{}
15	for _, o := range opts.geminiOptions {
16		o(&geminiOpts)
17	}
18
19	client, err := genai.NewClient(context.Background(), &genai.ClientConfig{
20		Project:  os.Getenv("GOOGLE_CLOUD_PROJECT"),
21		Location: os.Getenv("GOOGLE_CLOUD_LOCATION"),
22		Backend:  genai.BackendVertexAI,
23	})
24	if err != nil {
25		logging.Error("Failed to create VertexAI client", "error", err)
26		return nil
27	}
28
29	return &geminiClient{
30		providerOptions: opts,
31		options:         geminiOpts,
32		client:          client,
33	}
34}