chatgpt_test.go 699 B

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