summaryrefslogtreecommitdiff
path: root/doConnect.go.notyet
blob: 52fdc7cfc33034abff74cf33d0f4a48cae418f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/google/generative-ai-go/genai"
	"google.golang.org/api/option"
)

// doConnect initializes and returns a Gemini client.
// It reads the API key from the GEMINI_API_KEY environment variable.
func doConnect() (*genai.GenerativeModel, error) {
	apiKey := os.Getenv("GEMINI_API_KEY")
	if apiKey == "" {
		return nil, fmt.Errorf("GEMINI_API_KEY environment variable not set")
	}

	ctx := context.Background()
	client, err := genai.NewClient(ctx, option.WithAPIKey(apiKey))
	if err != nil {
		return nil, fmt.Errorf("failed to create new genai client: %w", err)
	}

	model := client.GenerativeModel("gemini-pro")
	return model, nil
}