-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
39 lines (31 loc) · 800 Bytes
/
session.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
package session
import (
"fmt"
"github.com/arthurweinmann/decisiontree/internal/settings"
"github.com/arthurweinmann/decisiontree/pkg/options"
"github.com/arthurweinmann/go-ai-sdk/pkg/openai"
"github.com/rs/xid"
)
type Session struct {
ID string
Settings *settings.Settings
}
func NewSession(opts ...options.Option) (*Session, error) {
sess := &Session{
ID: xid.New().String(),
Settings: settings.NewSettings(),
}
for _, opt := range opts {
opt.Apply(sess.Settings)
}
if sess.Settings.OpenAI != nil {
if sess.Settings.OpenAI.APIKey == "" {
return nil, fmt.Errorf("openai api key is empty")
}
err := openai.Init(sess.Settings.OpenAI.APIKey)
if err != nil {
return nil, fmt.Errorf("We could not setup openai sdk: %v", err)
}
}
return sess, nil
}