forked from coaidev/chatnio-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat_test.go
48 lines (40 loc) · 880 Bytes
/
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
package chatnio
import (
"fmt"
"github.com/whitiy666/chatnio-api-go/utils"
"testing"
)
func TestChat_AskStream(t *testing.T) {
if !instance.IsAuthenticated() {
return
}
chat, err := instance.NewChat(-1)
if err != nil {
return
}
defer chat.DeferClose()
chat.AskStream(&ChatRequestForm{
Message: "hello",
Model: "gpt-3.5-turbo",
}, func(resp ChatPartialResponse) {
fmt.Println(fmt.Sprintf("[chat] ask stream: %s", utils.MarshalForm(resp)))
})
}
func TestChat_Ask(t *testing.T) {
if !instance.IsAuthenticated() {
return
}
chat, err := instance.NewChat(-1)
if err != nil {
return
}
defer chat.DeferClose()
channel := make(chan ChatPartialResponse)
chat.Ask(&ChatRequestForm{
Message: "hello",
Model: "gpt-3.5-turbo",
}, channel)
for resp := range channel {
fmt.Println(fmt.Sprintf("[chat] ask: %s", utils.MarshalForm(resp)))
}
}