-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_test.go
149 lines (139 loc) · 3.83 KB
/
router_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package semantic_router
import (
"semantic_router/pkg/encoder"
"testing"
"github.com/stretchr/testify/require"
)
func TestMakeRoutingDecision(t *testing.T) {
techRoutes := []*Route{
{
Name: "kubernetes",
Metadata: RouteMetadata{
Utterances: []string{
"how do I deploy a pod in Kubernetes?",
"what is a Kubernetes namespace?",
"how can I check the status of my Kubernetes cluster?",
"how do I create a service?",
"why is my pod in CrashLoopBackOff state?",
"how do I create a network policy",
},
},
},
{
Name: "terraform",
Metadata: RouteMetadata{
Utterances: []string{
"how do I initialize a Terraform configuration?",
"what is the purpose of a Terraform provider?",
"how can I import existing infrastructure into Terraform?",
"why is my Terraform apply failing?",
"how do I use Terraform with AWS?",
},
},
},
{
Name: "linux",
Metadata: RouteMetadata{
Utterances: []string{
"how do I list all files in a directory in Linux?",
"what is the difference between a symlink and a hard link?",
"how do I check disk usage in Linux?",
"how can I change file permissions in Linux?",
"why is my shell script not executing?",
},
},
},
{
Name: "cicd",
Metadata: RouteMetadata{
Utterances: []string{
"how do I set up a CI/CD pipeline with Jenkins?",
"what is continuous integration?",
"how can I deploy code using GitHub Actions?",
"why is my CI build failing?",
"how do I implement continuous deployment?",
},
},
},
}
hrRoutes := []*Route{
{
Name: "hr_general",
Metadata: RouteMetadata{
Utterances: []string{
"what are the company policies on remote work?",
"how can I apply for leave?",
"what is the process for performance reviews?",
"how do I report workplace harassment?",
"what are the benefits of working here?",
},
},
},
{
Name: "hr_payroll",
Metadata: RouteMetadata{
Utterances: []string{
"when is payday?",
"how can I view my payslip?",
"what is the process for salary revision?",
"how do I update my bank details for payroll?",
"who do I contact for payroll issues?",
},
},
},
}
tt := []struct {
description string
routes []*Route
userInput string
expectedResult string
}{
{
description: "Identifies the expected route - Kubernetes",
routes: techRoutes,
userInput: "How do I create a service of type loadbalancer?",
expectedResult: "kubernetes",
},
{
description: "Identifies the expected route - Terraform",
routes: techRoutes,
userInput: "Why is my Terraform apply failing?",
expectedResult: "terraform",
},
{
description: "Identifies the expected route - Linux",
routes: techRoutes,
userInput: "How can I change file permissions in Linux?",
expectedResult: "linux",
},
{
description: "Identifies the expected route - CI/CD",
routes: techRoutes,
userInput: "Why is the pipeline taking so long?",
expectedResult: "cicd",
},
{
description: "Identifies the expected route - HR General",
routes: hrRoutes,
userInput: "What are the company policies on remote work?",
expectedResult: "hr_general",
},
{
description: "Identifies the expected route - HR Payroll",
routes: hrRoutes,
userInput: "When is payday?",
expectedResult: "hr_payroll",
},
}
enc, err := encoder.NewOpenAIEncoder("text-embedding-3-small")
require.NoError(t, err)
for _, test := range tt {
t.Run(test.description, func(t *testing.T) {
r, err := New(enc, test.routes)
require.NoError(t, err)
result, err := r.MakeRoutingDecision(test.userInput)
require.NoError(t, err)
require.Equal(t, test.expectedResult, result)
})
}
}