123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package chatgpt
- import (
- "os"
- "testing"
- )
- func TestOfflineContext(t *testing.T) {
- key := os.Getenv("CHATGPT_API_KEY")
- if key == "" {
- t.Skip("CHATGPT_API_KEY is not set")
- }
- cli := New("")
- reply, err := cli.ChatWithContext("我叫老三,你是?")
- if err != nil {
- t.Fatal(err)
- }
- t.Logf("我叫老三,你是? => %s", reply)
- err = cli.ChatContext.SaveConversation("test.conversation")
- if err != nil {
- t.Fatalf("储存对话记录失败: %v", err)
- }
- cli.ChatContext.ResetConversation("")
- reply, err = cli.ChatWithContext("你知道我是谁吗?")
- if err != nil {
- t.Fatal(err)
- }
- t.Logf("你知道我是谁吗? => %s", reply)
-
- err = cli.ChatContext.LoadConversation("test.conversation")
- if err != nil {
- t.Fatalf("读取对话记录失败: %v", err)
- }
- reply, err = cli.ChatWithContext("你知道我是谁吗?")
- if err != nil {
- t.Fatal(err)
- }
- t.Logf("你知道我是谁吗? => %s", reply)
-
-
- }
- func TestMaintainContext(t *testing.T) {
- key := os.Getenv("CHATGPT_API_KEY")
- if key == "" {
- t.Skip("CHATGPT_API_KEY is not set")
- }
- cli := New("")
- cli.ChatContext = NewContext(
- WithMaxSeqTimes(1),
- WithMaintainSeqTimes(true),
- )
- reply, err := cli.ChatWithContext("我叫老三,你是?")
- if err != nil {
- t.Fatal(err)
- }
- t.Logf("我叫老三,你是? => %s", reply)
- reply, err = cli.ChatWithContext("你知道我是谁吗?")
- if err != nil {
- t.Fatal(err)
- }
- t.Logf("你知道我是谁吗? => %s", reply)
-
-
- }
- func init() {
-
-
- }
|