1234567891011121314151617181920212223242526272829303132 |
- package chatgpt
- import (
- "fmt"
- "testing"
- "time"
- )
- 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)
- }
|