-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat_completion_test.go
53 lines (44 loc) · 1.18 KB
/
chat_completion_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
49
50
51
52
53
package openaiclient
import (
"os"
"testing"
"github.com/go-zoox/core-utils/fmt"
_ "github.com/go-zoox/dotenv"
)
func TestCreateChatCompletion(t *testing.T) {
client, _ := New(&Config{
APIKey: os.Getenv("OPENAI_API_KEY"),
// Proxy: "socks5://127.0.0.1:17890",
})
completion, err := client.CreateChatCompletion(&CreateChatCompletionRequest{
Model: "gpt-3.5-turbo",
Messages: []CreateChatCompletionMessage{
{Role: "user", Content: "你好用英语怎么说?"},
},
MaxTokens: 3000, // 4097
})
if err != nil {
t.Fatal(err)
}
fmt.PrintJSON(completion)
}
func TestCreateChatCompletionAzure(t *testing.T) {
client, _ := New(&Config{
APIKey: os.Getenv("OPENAI_API_KEY"),
APIType: APITypeAzure,
AzureResource: os.Getenv("AZURE_RESOURCE"),
AzureDeployment: os.Getenv("AZURE_DEPLOYMENT"),
AzureAPIVersion: os.Getenv("AZURE_API_VERSION"),
})
completion, err := client.CreateChatCompletion(&CreateChatCompletionRequest{
Model: "gpt-3.5-turbo",
Messages: []CreateChatCompletionMessage{
{Role: "user", Content: "你好用英语怎么说?"},
},
MaxTokens: 3000, // 4097
})
if err != nil {
t.Fatal(err)
}
fmt.PrintJSON(completion)
}