7
7
InvalidConstructorInput = iGetInvalidConstructorInput;
8
8
InvalidGenerateInput = iGetInvalidGenerateInput;
9
9
InvalidValuesSetters = iGetInvalidValuesSetters;
10
+ ValidValuesSetters = iGetValidValuesSetters;
10
11
end
11
12
12
13
methods (Test )
@@ -37,6 +38,26 @@ function doGenerate(testCase)
37
38
testCase .verifyGreaterThan(strlength(response ),0 );
38
39
end
39
40
41
+ function extremeTopK(testCase )
42
+ % setting top-k to k=1 leaves no random choice,
43
+ % so we expect to get a fixed response.
44
+ chat = ollamaChat(" mistral" ,TopProbabilityNum= 1 );
45
+ prompt = " Top-k sampling with k=1 returns a definite answer." ;
46
+ response1 = generate(chat ,prompt );
47
+ response2 = generate(chat ,prompt );
48
+ testCase .verifyEqual(response1 ,response2 );
49
+ end
50
+
51
+ function stopSequences(testCase )
52
+ chat = ollamaChat(" mistral" ,TopProbabilityNum= 1 );
53
+ prompt = " Top-k sampling with k=1 returns a definite answer." ;
54
+ response1 = generate(chat ,prompt );
55
+ chat.StopSequences = " 1" ;
56
+ response2 = generate(chat ,prompt );
57
+
58
+ testCase .verifyEqual(response2 , extractBefore(response1 ," 1" ));
59
+ end
60
+
40
61
%% Test is currently unreliable, reasons unclear
41
62
% function verySmallTimeOutErrors(testCase)
42
63
% chat = ollamaChat("mistral", TimeOut=1e-10);
@@ -60,6 +81,15 @@ function assignValueToProperty(property, value)
60
81
61
82
testCase .verifyError(@() assignValueToProperty(InvalidValuesSetters .Property ,InvalidValuesSetters .Value ), InvalidValuesSetters .Error );
62
83
end
84
+
85
+ function validSetters(testCase , ValidValuesSetters )
86
+ chat = ollamaChat(" mistral" );
87
+ function assignValueToProperty(property , value )
88
+ chat.(property ) = value ;
89
+ end
90
+
91
+ testCase .verifyWarningFree(@() assignValueToProperty(ValidValuesSetters .Property ,ValidValuesSetters .Value ));
92
+ end
63
93
end
64
94
end
65
95
@@ -119,17 +149,19 @@ function assignValueToProperty(property, value)
119
149
" EmptyStopSequences" , struct( ...
120
150
" Property" , " StopSequences" , ...
121
151
" Value" , " " , ...
122
- " Error" , " MATLAB:validators:mustBeNonzeroLengthText" ), ...
123
- ...
124
- " WrongSizeStopSequences" , struct( ...
125
- " Property" , " StopSequences" , ...
126
- " Value" , [" 1" " 2" " 3" " 4" " 5" ], ...
127
- " Error" , " llms:stopSequencesMustHaveMax4Elements" ), ...
128
- ...
129
- " InvalidPresencePenalty" , struct( ...
130
- " Property" , " PresencePenalty" , ...
131
- " Value" , " 2" , ...
132
- " Error" , " MATLAB:invalidType" ));
152
+ " Error" , " MATLAB:validators:mustBeNonzeroLengthText" ));
153
+ end
154
+
155
+ function validSetters = iGetValidValuesSetters
156
+ validSetters = struct(...
157
+ " SmallTopNum" , struct( ...
158
+ " Property" , " TopProbabilityNum" , ...
159
+ " Value" , 2 ));
160
+ % Currently disabled because it requires some code reorganization
161
+ % and we have higher priorities ...
162
+ % "ManyStopSequences", struct( ...
163
+ % "Property", "StopSequences", ...
164
+ % "Value", ["1" "2" "3" "4" "5"]));
133
165
end
134
166
135
167
function invalidConstructorInput = iGetInvalidConstructorInput
@@ -196,7 +228,7 @@ function assignValueToProperty(property, value)
196
228
...
197
229
" TopProbabilityMassTooSmall" ,struct( ...
198
230
" Input" ,{{ " TopProbabilityMass" - 20 }},...
199
- " Error" ," MATLAB:expectedNonnegative" ),...
231
+ " Error" ," MATLAB:expectedNonnegative" ),...I
200
232
...
201
233
" WrongTypeStopSequences" ,struct( ...
202
234
" Input" ,{{ " StopSequences" 123 }},...
@@ -208,11 +240,7 @@ function assignValueToProperty(property, value)
208
240
...
209
241
" EmptyStopSequences" ,struct( ...
210
242
" Input" ,{{ " StopSequences" " " }},...
211
- " Error" ," MATLAB:validators:mustBeNonzeroLengthText" ),...
212
- ...
213
- " WrongSizeStopSequences" ,struct( ...
214
- " Input" ,{{ " StopSequences" [" 1" " 2" " 3" " 4" " 5" ]}},...
215
- " Error" ," llms:stopSequencesMustHaveMax4Elements" ));
243
+ " Error" ," MATLAB:validators:mustBeNonzeroLengthText" ));
216
244
end
217
245
218
246
function invalidGenerateInput = iGetInvalidGenerateInput
0 commit comments