-
Notifications
You must be signed in to change notification settings - Fork 0
/
goai.go
58 lines (54 loc) · 1.22 KB
/
goai.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
package goai
import (
"hash/fnv"
"net/http"
"strconv"
"time"
)
type Client struct {
Endpoint string
API_KEY string
Verbose bool
User string
HTTPClient *http.Client
ImageSize string
TopP float64
ChatModel string
ImageModel string
TTSModel string
Voice string
Speed float64
ResponseFormat string
MaxTokens int
Temperature float64
FrequencyPenalty float64
PresencePenalty float64
}
// Create a unique user for OpenAI to track
func HashAPIKey(apiKey string) string {
h := fnv.New64a()
h.Write([]byte(apiKey))
return strconv.FormatUint(h.Sum64(), 10)
}
func DefaultClient(apiKey string, verbose bool) *Client {
return &Client{
API_KEY: apiKey,
Verbose: verbose,
Endpoint: "https://api.openai.com/v1/",
User: HashAPIKey(apiKey),
HTTPClient: &http.Client{
Timeout: time.Second * 60,
},
ImageSize: "1024x1024",
TopP: 0.9,
ChatModel: "gpt-4",
TTSModel: "tts-1",
Voice: "onyx",
Speed: 1,
ResponseFormat: "mp3",
MaxTokens: 999,
Temperature: 0.9,
FrequencyPenalty: 0.03,
PresencePenalty: 0.6,
}
}