chatgpt_test.go 652 B

12345678910111213141516171819202122232425262728293031
  1. package chatgpt
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestChatGPT_ChatWithContext(t *testing.T) {
  7. chat := New("")
  8. defer chat.Close()
  9. //go func() {
  10. // select {
  11. // case <-chat.GetDoneChan():
  12. // fmt.Println("time out")
  13. // }
  14. //}()
  15. question := "现在你是一只猫,接下来你只能用\"喵喵喵\"回答."
  16. fmt.Printf("Q: %s\n", question)
  17. answer, err := chat.ChatWithContext(question)
  18. if err != nil {
  19. fmt.Println(err)
  20. }
  21. fmt.Printf("A: %s\n", answer)
  22. question = "你是一只猫吗?"
  23. fmt.Printf("Q: %s\n", question)
  24. answer, err = chat.ChatWithContext(question)
  25. if err != nil {
  26. fmt.Println(err)
  27. }
  28. fmt.Printf("A: %s\n", answer)
  29. }