forked from mudler/cogito
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoal_e2e_test.go
More file actions
66 lines (54 loc) · 1.94 KB
/
Copy pathgoal_e2e_test.go
File metadata and controls
66 lines (54 loc) · 1.94 KB
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
62
63
64
65
66
package cogito_test
import (
"strings"
. "github.com/mudler/cogito"
"github.com/mudler/cogito/clients"
"github.com/mudler/cogito/structures"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("cogito test", Label("e2e"), func() {
Context("Goals", func() {
It("is able to extract a goal", func() {
defaultLLM := clients.NewOpenAILLM(defaultModel, "", apiEndpoint)
conv := NewEmptyFragment().AddMessage("user", "You need to search all informations you can about Isaac Asimov.")
goal, err := ExtractGoal(defaultLLM, conv)
Expect(err).ToNot(HaveOccurred())
Expect(goal.Goal).ToNot(BeEmpty())
Expect(strings.ToLower(goal.Goal)).To(ContainSubstring("isaac asimov"))
})
It("uderstands when a goal is reached", func() {
defaultLLM := clients.NewOpenAILLM(defaultModel, "", apiEndpoint)
conv := NewEmptyFragment().AddMessage("user", "What are the latest news today?")
goal, err := ExtractGoal(defaultLLM, conv)
Expect(err).ToNot(HaveOccurred())
var achieved *structures.Boolean
for range 4 { // Simulate an "infinite loop"
searchTool := &SearchTool{
results: []string{
"India warns new US fee for H-1B visa will have 'humanitarian consequences' - bbc.com",
"Estonia seeks Nato consultation after Russian jets violate airspace - bbc.com",
"Day of delays at Heathrow after cyber-attack brings disruption - bbc.com",
"Kildunne stars as England see off France to make final - bbc.com",
},
}
conv, err = ExecuteTools(defaultLLM, conv, WithTools(
NewToolDefinition(
searchTool,
SearchArgs{},
"search",
"A search engine to find information about a topic",
),
))
Expect(err).ToNot(HaveOccurred())
achieved, err = IsGoalAchieved(defaultLLM, conv, goal)
Expect(err).ToNot(HaveOccurred())
if achieved.Boolean {
break
}
}
Expect(achieved).ToNot(BeNil())
Expect(achieved.Boolean).To(BeTrue())
})
})
})