-
Notifications
You must be signed in to change notification settings - Fork 65
/
client_options.go
60 lines (52 loc) · 1.62 KB
/
client_options.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
package gpt3
import (
"net/http"
"time"
)
// ClientOption are options that can be passed when creating a new client
type ClientOption func(*client) error
// WithOrg is a client option that allows you to override the organization ID
func WithOrg(id string) ClientOption {
return func(c *client) error {
c.idOrg = id
return nil
}
}
// WithDefaultEngine is a client option that allows you to override the default engine of the client
func WithDefaultEngine(engine string) ClientOption {
return func(c *client) error {
c.defaultEngine = engine
return nil
}
}
// WithUserAgent is a client option that allows you to override the default user agent of the client
func WithUserAgent(userAgent string) ClientOption {
return func(c *client) error {
c.userAgent = userAgent
return nil
}
}
// WithBaseURL is a client option that allows you to override the default base url of the client.
// The default base url is "https://api.openai.com/v1"
func WithBaseURL(baseURL string) ClientOption {
return func(c *client) error {
c.baseURL = baseURL
return nil
}
}
// WithHTTPClient allows you to override the internal http.Client used
func WithHTTPClient(httpClient *http.Client) ClientOption {
return func(c *client) error {
c.httpClient = httpClient
return nil
}
}
// WithTimeout is a client option that allows you to override the default timeout duration of requests
// for the client. The default is 30 seconds. If you are overriding the http client as well, just include
// the timeout there.
func WithTimeout(timeout time.Duration) ClientOption {
return func(c *client) error {
c.httpClient.Timeout = timeout
return nil
}
}