forked from liushuangls/go-anthropic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
84 lines (65 loc) · 1.54 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
79
80
81
82
83
84
package anthropic
import (
"net/http"
)
const (
anthropicAPIURLv1 = "https://api.anthropic.com/v1"
defaultEmptyMessagesLimit uint = 300
)
const (
APIVersion20230601 = "2023-06-01"
)
const (
BetaTools20240404 = "tools-2024-04-04"
BetaTools20240516 = "tools-2024-05-16"
BetaPromptCaching20240731 = "prompt-caching-2024-07-31"
BetaMaxTokens35Sonnet20240715 = "max-tokens-3-5-sonnet-2024-07-15"
)
// ClientConfig is a configuration of a client.
type ClientConfig struct {
apiKey string
BaseURL string
APIVersion string
BetaVersion string
HTTPClient *http.Client
EmptyMessagesLimit uint
}
type ClientOption func(c *ClientConfig)
func newConfig(apiKey string, opts ...ClientOption) ClientConfig {
c := ClientConfig{
apiKey: apiKey,
BaseURL: anthropicAPIURLv1,
APIVersion: APIVersion20230601,
HTTPClient: &http.Client{},
EmptyMessagesLimit: defaultEmptyMessagesLimit,
}
for _, opt := range opts {
opt(&c)
}
return c
}
func WithBaseURL(baseUrl string) ClientOption {
return func(c *ClientConfig) {
c.BaseURL = baseUrl
}
}
func WithAPIVersion(apiVersion string) ClientOption {
return func(c *ClientConfig) {
c.APIVersion = apiVersion
}
}
func WithHTTPClient(cli *http.Client) ClientOption {
return func(c *ClientConfig) {
c.HTTPClient = cli
}
}
func WithEmptyMessagesLimit(limit uint) ClientOption {
return func(c *ClientConfig) {
c.EmptyMessagesLimit = limit
}
}
func WithBetaVersion(betaVersion string) ClientOption {
return func(c *ClientConfig) {
c.BetaVersion = betaVersion
}
}