-
-
Notifications
You must be signed in to change notification settings - Fork 701
/
Copy pathnew.go
41 lines (33 loc) · 916 Bytes
/
new.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
// package googleai implements a langchaingo provider for Google AI LLMs.
// See https://ai.google.dev/ for more details.
package googleai
import (
"context"
"github.com/google/generative-ai-go/genai"
"github.com/tmc/langchaingo/callbacks"
"github.com/tmc/langchaingo/llms"
)
// GoogleAI is a type that represents a Google AI API client.
type GoogleAI struct {
CallbacksHandler callbacks.Handler
client *genai.Client
opts Options
}
var _ llms.Model = &GoogleAI{}
// New creates a new GoogleAI client.
func New(ctx context.Context, opts ...Option) (*GoogleAI, error) {
clientOptions := DefaultOptions()
for _, opt := range opts {
opt(&clientOptions)
}
clientOptions.EnsureAuthPresent()
gi := &GoogleAI{
opts: clientOptions,
}
client, err := genai.NewClient(ctx, clientOptions.ClientOptions...)
if err != nil {
return gi, err
}
gi.client = client
return gi, nil
}