-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversation_test.go
61 lines (48 loc) · 1.45 KB
/
conversation_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
54
55
56
57
58
59
60
61
package conversation_test
import (
"os"
"path/filepath"
. "github.com/mudler/go-chatgpt-conversation"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/otiai10/openaigo"
)
var _ = Describe("ask to gpt", func() {
Context("conversation", func() {
It("can track history", func() {
if os.Getenv("OPENAI_API_TOKEN") == "" {
Skip("OPENAI_API_TOKEN required to run this test")
}
cat, err := New(os.Getenv("OPENAI_API_TOKEN"),
WithInitialPrompt("You are a cat. You can reply with 'Meow' for yes, and 'Meow Meow' for no."))
Expect(err).ToNot(HaveOccurred())
res, err := cat.User("Are you a cat?")
Expect(err).ToNot(HaveOccurred())
Expect(res).To(Equal("Meow."))
res, err = cat.Chat("Are you a human?")
Expect(err).ToNot(HaveOccurred())
Expect(res).To(Equal("Meow Meow."))
})
It("can save history", func() {
testHistory := []openaigo.ChatMessage{
{Role: "system", Content: "foo"},
{Role: "user", Content: "bar"},
{Role: "assistant", Content: "response"}}
cat, err := New("none",
WithHistory(
testHistory,
),
)
Expect(err).ToNot(HaveOccurred())
dir, err := os.MkdirTemp("", "test")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(dir)
f := filepath.Join(dir, "test.json")
err = cat.Save(f)
Expect(err).ToNot(HaveOccurred())
conv, err := Load(f, "test")
Expect(err).ToNot(HaveOccurred())
Expect(conv.History).To(Equal(testHistory))
})
})
})