-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_test.go
More file actions
179 lines (151 loc) · 3.54 KB
/
Copy pathoptions_test.go
File metadata and controls
179 lines (151 loc) · 3.54 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package modelsocket
import "testing"
func TestGenOption_MaxTokens(t *testing.T) {
cfg := genConfig{}
WithMaxTokens(500)(&cfg)
if cfg.maxTokens == nil {
t.Fatal("maxTokens is nil")
}
if *cfg.maxTokens != 500 {
t.Errorf("maxTokens = %d, want 500", *cfg.maxTokens)
}
}
func TestGenOption_Temperature(t *testing.T) {
cfg := genConfig{}
WithTemperature(0.8)(&cfg)
if cfg.temperature == nil {
t.Fatal("temperature is nil")
}
if *cfg.temperature != 0.8 {
t.Errorf("temperature = %f, want 0.8", *cfg.temperature)
}
}
func TestGenOption_TopP(t *testing.T) {
cfg := genConfig{}
WithTopP(0.9)(&cfg)
if cfg.topP == nil {
t.Fatal("topP is nil")
}
if *cfg.topP != 0.9 {
t.Errorf("topP = %f, want 0.9", *cfg.topP)
}
}
func TestGenOption_TopK(t *testing.T) {
cfg := genConfig{}
WithTopK(40)(&cfg)
if cfg.topK == nil {
t.Fatal("topK is nil")
}
if *cfg.topK != 40 {
t.Errorf("topK = %d, want 40", *cfg.topK)
}
}
func TestGenOption_StopStrings(t *testing.T) {
cfg := genConfig{}
WithStopStrings("STOP", "END", "DONE")(&cfg)
if len(cfg.stopStrings) != 3 {
t.Fatalf("len(stopStrings) = %d, want 3", len(cfg.stopStrings))
}
if cfg.stopStrings[0] != "STOP" {
t.Errorf("stopStrings[0] = %s, want STOP", cfg.stopStrings[0])
}
}
func TestGenOption_Hidden(t *testing.T) {
cfg := genConfig{}
WithHidden()(&cfg)
if !cfg.hidden {
t.Error("hidden = false, want true")
}
}
func TestGenOption_Seed(t *testing.T) {
cfg := genConfig{}
WithSeed(42)(&cfg)
if cfg.seed == nil {
t.Fatal("seed is nil")
}
if *cfg.seed != 42 {
t.Errorf("seed = %d, want 42", *cfg.seed)
}
}
func TestGenOption_Role(t *testing.T) {
tests := []struct {
name string
option GenOption
want Role
}{
{"User", GenerateAsUser(), RoleUser},
{"Assistant", GenerateAsAssistant(), RoleAssistant},
{"System", GenerateAsSystem(), RoleSystem},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := genConfig{}
tt.option(&cfg)
if cfg.role != tt.want {
t.Errorf("role = %s, want %s", cfg.role, tt.want)
}
})
}
}
func TestAppendOption_Role(t *testing.T) {
tests := []struct {
name string
option AppendOption
want Role
}{
{"User", AsUser(), RoleUser},
{"Assistant", AsAssistant(), RoleAssistant},
{"System", AsSystem(), RoleSystem},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := appendConfig{}
tt.option(&cfg)
if cfg.role != tt.want {
t.Errorf("role = %s, want %s", cfg.role, tt.want)
}
})
}
}
func TestAppendOption_Echo(t *testing.T) {
cfg := appendConfig{}
WithEcho()(&cfg)
if !cfg.echo {
t.Error("echo = false, want true")
}
}
func TestOpenOption_SkipPrelude(t *testing.T) {
cfg := openConfig{}
WithSkipPrelude()(&cfg)
if !cfg.skipPrelude {
t.Error("skipPrelude = false, want true")
}
}
func TestOpenOption_Toolbox(t *testing.T) {
tb := NewToolbox()
cfg := openConfig{}
WithToolbox(tb)(&cfg)
if cfg.toolbox != tb {
t.Error("toolbox not set correctly")
}
}
func TestGenConfig_ToSeqGenData(t *testing.T) {
cfg := genConfig{}
GenerateAsAssistant()(&cfg)
WithMaxTokens(100)(&cfg)
WithTemperature(0.7)(&cfg)
WithStopStrings("END")(&cfg)
data := cfg.toSeqGenData()
if data.Role != "assistant" {
t.Errorf("Role = %s, want assistant", data.Role)
}
if *data.MaxTokens != 100 {
t.Errorf("MaxTokens = %d, want 100", *data.MaxTokens)
}
if *data.Temperature != 0.7 {
t.Errorf("Temperature = %f, want 0.7", *data.Temperature)
}
if len(data.StopStrings) != 1 || data.StopStrings[0] != "END" {
t.Errorf("StopStrings = %v, want [END]", data.StopStrings)
}
}