forked from sashabaranov/go-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openai_test.go
48 lines (43 loc) · 1.46 KB
/
openai_test.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
package openai_test
import (
"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/internal/test"
)
func setupOpenAITestServer() (client *openai.Client, server *test.ServerTest, teardown func()) {
server = test.NewTestServer()
ts := server.OpenAITestServer()
ts.Start()
teardown = ts.Close
config := openai.DefaultConfig(test.GetTestToken())
config.BaseURL = ts.URL + "/v1"
client = openai.NewClientWithConfig(config)
return
}
func setupAzureTestServer() (client *openai.Client, server *test.ServerTest, teardown func()) {
server = test.NewTestServer()
ts := server.OpenAITestServer()
ts.Start()
teardown = ts.Close
config := openai.DefaultAzureConfig(test.GetTestToken(), "https://dummylab.openai.azure.com/")
config.BaseURL = ts.URL
client = openai.NewClientWithConfig(config)
return
}
func setupGroqTestServer() (client *openai.Client, server *test.ServerTest, teardown func()) {
server = test.NewTestServer()
ts := server.OpenAITestServer()
ts.Start()
teardown = ts.Close
config := openai.DefaultGroqConfig(test.GetTestToken())
config.BaseURL = ts.URL + "/v1"
client = openai.NewClientWithConfig(config)
return
}
// numTokens Returns the number of GPT-3 encoded tokens in the given text.
// This function approximates based on the rule of thumb stated by OpenAI:
// https://beta.openai.com/tokenizer
//
// TODO: implement an actual tokenizer for GPT-3 and Codex (once available)
func numTokens(s string) int {
return int(float32(len(s)) / 4)
}