forked from hanyuancheung/gpt-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
70 lines (60 loc) · 1.87 KB
/
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
61
62
63
64
65
66
67
68
69
70
// Package gpt provides a client for the OpenAI GPT-3 API
package gpt
import (
"net/http"
"time"
)
// Option sets gpt-3 Client option values.
type Option interface {
apply(client) error
}
// ClientOption are options that can be passed when creating a new client
type ClientOption func(*client) *client
func (fn ClientOption) apply(cli *client) *client {
return fn(cli)
}
// WithOrg is a client option that allows you to override the organization ID
func WithOrg(id string) ClientOption {
return func(cli *client) *client {
cli.idOrg = id
return cli
}
}
// WithDefaultEngine is a client option that allows you to override the default engine of the client
func WithDefaultEngine(engine string) ClientOption {
return func(cli *client) *client {
cli.defaultEngine = engine
return cli
}
}
// WithUserAgent is a client option that allows you to override the default user agent of the client
func WithUserAgent(userAgent string) ClientOption {
return func(cli *client) *client {
cli.userAgent = userAgent
return cli
}
}
// 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(cli *client) *client {
cli.baseURL = baseURL
return cli
}
}
// WithHTTPClient allows you to override the internal http.Client used
func WithHTTPClient(httpClient *http.Client) ClientOption {
return func(cli *client) *client {
cli.httpClient = httpClient
return cli
}
}
// 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(cli *client) *client {
cli.httpClient.Timeout = timeout
return cli
}
}