-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
78 lines (58 loc) · 1.89 KB
/
config.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ai
type ClientConfig struct {
LLMs LLMs
APIKey string
Endpoint string
Proxy string
Limit *int64
Model string
ModelConfig ModelConfig
}
type ModelConfig struct {
Count *int64
MaxTokens *int64
Temperature *float64
TopP *float64
JSONResponse *bool
Tools []Function
ToolConfig FunctionCallingMode
}
func ApplyModelConfig(ai AI, cfg ModelConfig) {
if cfg.Count != nil {
ai.SetCount(*cfg.Count)
}
if cfg.MaxTokens != nil {
ai.SetMaxTokens(*cfg.MaxTokens)
}
if cfg.Temperature != nil {
ai.SetTemperature(*cfg.Temperature)
}
if cfg.TopP != nil {
ai.SetTopP(*cfg.TopP)
}
if cfg.JSONResponse != nil {
ai.SetJSONResponse(*cfg.JSONResponse)
}
ai.SetFunctionCall(cfg.Tools, cfg.ToolConfig)
}
type ClientOption interface {
Apply(*ClientConfig)
}
func WithAPIKey(apiKey string) ClientOption { return withAPIKey(apiKey) }
func WithEndpoint(endpoint string) ClientOption { return withEndpoint(endpoint) }
func WithProxy(proxy string) ClientOption { return withProxy(proxy) }
func WithLimit(rpm int64) ClientOption { return withLimit(rpm) }
func WithModel(model string) ClientOption { return withModel(model) }
func WithModelConfig(config ModelConfig) ClientOption { return withModelConfig(config) }
type withAPIKey string
func (w withAPIKey) Apply(cfg *ClientConfig) { cfg.APIKey = string(w) }
type withEndpoint string
func (w withEndpoint) Apply(cfg *ClientConfig) { cfg.Endpoint = string(w) }
type withProxy string
func (w withProxy) Apply(cfg *ClientConfig) { cfg.Proxy = string(w) }
type withLimit int64
func (w withLimit) Apply(cfg *ClientConfig) { cfg.Limit = (*int64)(&w) }
type withModel string
func (w withModel) Apply(cfg *ClientConfig) { cfg.Model = string(w) }
type withModelConfig ModelConfig
func (w withModelConfig) Apply(cfg *ClientConfig) { cfg.ModelConfig = ModelConfig(w) }