vertexai.go 692 B

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