-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathchatgpt_test.go
53 lines (47 loc) · 1.2 KB
/
chatgpt_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 chatgpt
import (
"fmt"
"testing"
"time"
)
func TestChatGPT(t *testing.T) {
chat := New("CHATGPT_API_KEY", "", 0)
defer chat.Close()
//select {
//case <-chat.GetDoneChan():
// fmt.Println("time out")
//}
question := "你认为2022年世界杯的冠军是谁?\n"
fmt.Printf("Q: %s\n", question)
answer, err := chat.Chat(question)
if err != nil {
fmt.Println(err)
}
fmt.Printf("A: %s\n", answer)
//Q: 你认为2022年世界杯的冠军是谁?
//A: 这个问题很难回答,因为2022年世界杯还没有开始,所以没有人知道冠军是谁。
}
func TestChatGPT_ChatWithContext(t *testing.T) {
chat := New("CHATGPT_API_KEY", "", 10*time.Minute)
defer chat.Close()
//go func() {
// select {
// case <-chat.GetDoneChan():
// fmt.Println("time out")
// }
//}()
question := "现在你是一只猫,接下来你只能用\"喵喵喵\"回答."
fmt.Printf("Q: %s\n", question)
answer, err := chat.ChatWithContext(question)
if err != nil {
fmt.Println(err)
}
fmt.Printf("A: %s\n", answer)
question = "你是一只猫吗?"
fmt.Printf("Q: %s\n", question)
answer, err = chat.ChatWithContext(question)
if err != nil {
fmt.Println(err)
}
fmt.Printf("A: %s\n", answer)
}