-
Notifications
You must be signed in to change notification settings - Fork 36
/
chat_test.go
67 lines (62 loc) · 1.49 KB
/
chat_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package openaigo
import (
"sync"
"testing"
. "github.com/otiai10/mint"
)
func TestClient_ChatCompletion(t *testing.T) {
client := NewClient("")
client.BaseURL = mockserver.URL
res, err := client.ChatCompletion(nil, ChatCompletionRequestBody{
Model: GPT3_5Turbo,
})
Expect(t, err).ToBe(nil)
Expect(t, res).TypeOf("openaigo.ChatCompletionResponse")
}
func TestClient_ChatCompletion_Stream(t *testing.T) {
client := NewClient("")
client.BaseURL = mockserver.URL
wg := sync.WaitGroup{}
wg.Add(2)
res, err := client.ChatCompletion(nil, ChatCompletionRequestBody{
Model: GPT3_5Turbo,
Stream: true,
StreamCallback: func(res ChatCompletionResponse, done bool, err error) {
Expect(t, err).ToBe(nil)
wg.Done()
},
})
Expect(t, err).ToBe(nil)
Expect(t, res).TypeOf("openaigo.ChatCompletionResponse")
wg.Wait()
}
func TestClient_ChatCompletion_FunctionCall(t *testing.T) {
client := NewClient("")
client.BaseURL = mockserver.URL
res, err := client.Chat(nil, ChatRequest{
Model: GPT3_5Turbo,
Messages: []Message{
{
Role: "user", Content: "Hello, I'm John.",
},
},
Functions: Functions{
{
Name: "test_method",
Parameters: Parameters{
Type: "object",
Properties: map[string]map[string]any{
"arg_0": {
"type": "string",
"description": "This is a test",
},
},
Required: []string{"arg_0"},
},
},
},
FunctionCall: "auto",
})
Expect(t, err).ToBe(nil)
Expect(t, res).TypeOf("openaigo.ChatCompletionResponse")
}