-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.go
More file actions
93 lines (83 loc) · 2.05 KB
/
options.go
File metadata and controls
93 lines (83 loc) · 2.05 KB
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
85
86
87
88
89
90
91
92
93
package goai
import (
"time"
)
// Options contains configuration options for LLM providers
type Options struct {
APIKey string
Endpoint string
Timeout time.Duration
MaxTokens int
Temperature float64
}
// Option is a functional option for configuring a Client
type Option func(*Options)
// defaultOptions returns default options
func defaultOptions() Options {
return Options{
Timeout: 60 * time.Second,
MaxTokens: 500,
Temperature: 0.7,
}
}
// WithAPIKey sets the API key for the provider
//
// Example:
// client := goai.New("openai", "gpt-4o",
// goai.WithAPIKey(os.Getenv("OPENAI_API_KEY")),
// )
func WithAPIKey(key string) Option {
return func(o *Options) {
o.APIKey = key
}
}
// WithEndpoint sets a custom API endpoint
//
// Example:
// client := goai.New("openai", "gpt-4o",
// goai.WithAPIKey(apiKey),
// goai.WithEndpoint("https://api.openai.com/v1/chat/completions"),
// )
func WithEndpoint(url string) Option {
return func(o *Options) {
o.Endpoint = url
}
}
// WithTimeout sets the timeout for API requests
//
// Example:
// client := goai.New("openai", "gpt-4o",
// goai.WithAPIKey(apiKey),
// goai.WithTimeout(30*time.Second),
// )
func WithTimeout(d time.Duration) Option {
return func(o *Options) {
o.Timeout = d
}
}
// WithMaxTokens sets the maximum number of tokens in the response
//
// Example:
// client := goai.New("openai", "gpt-4o",
// goai.WithAPIKey(apiKey),
// goai.WithMaxTokens(1000),
// )
func WithMaxTokens(n int) Option {
return func(o *Options) {
o.MaxTokens = n
}
}
// WithTemperature sets the temperature for response generation
//
// Temperature controls randomness: 0.0 is deterministic, higher values are more random.
//
// Example:
// client := goai.New("openai", "gpt-4o",
// goai.WithAPIKey(apiKey),
// goai.WithTemperature(0.9),
// )
func WithTemperature(t float64) Option {
return func(o *Options) {
o.Temperature = t
}
}