Skip to content

Commit 70baea5

Browse files
committed
More specific error messages: “numeric,” not “numeric or logical”
1 parent 25b8ffc commit 70baea5

11 files changed

+43
-39
lines changed

Diff for: azureChat.m

+5-4
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
nvp.ResponseFormat {llms.utils.mustBeResponseFormat} = "text"
115115
nvp.PresencePenalty {llms.utils.mustBeValidPenalty} = 0
116116
nvp.FrequencyPenalty {llms.utils.mustBeValidPenalty} = 0
117-
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 10
117+
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 10
118118
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
119119
end
120120

@@ -225,10 +225,10 @@
225225
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar} = this.APIKey
226226
nvp.PresencePenalty {llms.utils.mustBeValidPenalty} = this.PresencePenalty
227227
nvp.FrequencyPenalty {llms.utils.mustBeValidPenalty} = this.FrequencyPenalty
228-
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = this.TimeOut
228+
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = this.TimeOut
229229
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
230-
nvp.NumCompletions (1,1) {mustBePositive, mustBeInteger} = 1
231-
nvp.MaxNumTokens (1,1) {mustBePositive} = inf
230+
nvp.NumCompletions (1,1) {mustBeNumeric,mustBePositive, mustBeInteger} = 1
231+
nvp.MaxNumTokens (1,1) {mustBeNumeric,mustBePositive} = inf
232232
nvp.ToolChoice {mustBeValidFunctionCall(this, nvp.ToolChoice)} = []
233233
nvp.Seed {mustBeIntegerOrEmpty(nvp.Seed)} = []
234234
end
@@ -353,6 +353,7 @@ function mustBeValidMsgs(value)
353353

354354
function mustBeIntegerOrEmpty(value)
355355
if ~isempty(value)
356+
mustBeNumeric(value)
356357
mustBeInteger(value)
357358
end
358359
end

Diff for: extractOpenAIEmbeddings.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
text (1,:) {mustBeNonzeroLengthText}
2727
nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["text-embedding-ada-002", ...
2828
"text-embedding-3-large", "text-embedding-3-small"])} = "text-embedding-ada-002"
29-
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 10
30-
nvp.Dimensions (1,1) {mustBeInteger,mustBePositive}
29+
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 10
30+
nvp.Dimensions (1,1) {mustBeNumeric,mustBeInteger,mustBePositive}
3131
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar}
3232
end
3333

@@ -62,6 +62,7 @@ function mustBeCorrectDimensions(dimensions,modelName)
6262
dictionary(["text-embedding-3-large", "text-embedding-3-small"], ...
6363
[3072,1536]);
6464

65+
mustBeNumeric(dimensions);
6566
if dimensions>model2dim(modelName)
6667
error("llms:dimensionsMustBeSmallerThan", ...
6768
llms.utils.errorMessageCatalog.getMessage("llms:dimensionsMustBeSmallerThan", ...

Diff for: messageHistory.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211

212212
arguments
213213
this (1,1) messageHistory
214-
idx (1,1) {mustBeInteger, mustBePositive}
214+
idx (1,1) {mustBeNumeric,mustBeInteger,mustBePositive}
215215
end
216216
if isempty(this.Messages)
217217
error("llms:removeFromEmptyHistory",llms.utils.errorMessageCatalog.getMessage("llms:removeFromEmptyHistory"));

Diff for: ollamaChat.m

+9-8
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
properties
7272
ModelName (1,1) string
7373
Endpoint (1,1) string
74-
TopK (1,1) {mustBeReal,mustBePositive} = Inf
74+
TopK (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = Inf
7575
MinP (1,1) {llms.utils.mustBeValidProbability} = 0
76-
TailFreeSamplingZ (1,1) {mustBeReal} = 1
76+
TailFreeSamplingZ (1,1) {mustBeNumeric,mustBeReal} = 1
7777
end
7878

7979
methods
@@ -87,8 +87,8 @@
8787
nvp.TopK (1,1) {mustBeReal,mustBePositive} = Inf
8888
nvp.StopSequences {llms.utils.mustBeValidStop} = {}
8989
nvp.ResponseFormat (1,1) string {mustBeMember(nvp.ResponseFormat,["text","json"])} = "text"
90-
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 120
91-
nvp.TailFreeSamplingZ (1,1) {mustBeReal} = 1
90+
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 120
91+
nvp.TailFreeSamplingZ (1,1) {mustBeNumeric,mustBeReal} = 1
9292
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
9393
nvp.Endpoint (1,1) string = "127.0.0.1:11434"
9494
end
@@ -190,14 +190,14 @@
190190
nvp.Temperature {llms.utils.mustBeValidTemperature} = this.Temperature
191191
nvp.TopP {llms.utils.mustBeValidProbability} = this.TopP
192192
nvp.MinP {llms.utils.mustBeValidProbability} = this.MinP
193-
nvp.TopK (1,1) {mustBeReal,mustBePositive} = this.TopK
193+
nvp.TopK (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = this.TopK
194194
nvp.StopSequences {llms.utils.mustBeValidStop} = this.StopSequences
195195
nvp.ResponseFormat {llms.utils.mustBeResponseFormat} = this.ResponseFormat
196-
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = this.TimeOut
197-
nvp.TailFreeSamplingZ (1,1) {mustBeReal} = this.TailFreeSamplingZ
196+
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = this.TimeOut
197+
nvp.TailFreeSamplingZ (1,1) {mustBeNumeric,mustBeReal} = this.TailFreeSamplingZ
198198
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
199199
nvp.Endpoint (1,1) string = this.Endpoint
200-
nvp.MaxNumTokens (1,1) {mustBePositive} = inf
200+
nvp.MaxNumTokens (1,1) {mustBeNumeric,mustBePositive} = inf
201201
nvp.Seed {mustBeIntegerOrEmpty(nvp.Seed)} = []
202202
end
203203

@@ -313,6 +313,7 @@ function mustBeValidMsgs(value)
313313

314314
function mustBeIntegerOrEmpty(value)
315315
if ~isempty(value)
316+
mustBeNumeric(value)
316317
mustBeInteger(value)
317318
end
318319
end

Diff for: openAIChat.m

+5-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar}
102102
nvp.PresencePenalty {llms.utils.mustBeValidPenalty} = 0
103103
nvp.FrequencyPenalty {llms.utils.mustBeValidPenalty} = 0
104-
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 10
104+
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 10
105105
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
106106
end
107107

@@ -218,10 +218,10 @@
218218
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar} = this.APIKey
219219
nvp.PresencePenalty {llms.utils.mustBeValidPenalty} = this.PresencePenalty
220220
nvp.FrequencyPenalty {llms.utils.mustBeValidPenalty} = this.FrequencyPenalty
221-
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = this.TimeOut
221+
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = this.TimeOut
222222
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
223-
nvp.NumCompletions (1,1) {mustBePositive, mustBeInteger} = 1
224-
nvp.MaxNumTokens (1,1) {mustBePositive} = inf
223+
nvp.NumCompletions (1,1) {mustBeNumeric,mustBePositive, mustBeInteger} = 1
224+
nvp.MaxNumTokens (1,1) {mustBeNumeric,mustBePositive} = inf
225225
nvp.ToolChoice {mustBeValidFunctionCall(this, nvp.ToolChoice)} = []
226226
nvp.Seed {mustBeIntegerOrEmpty(nvp.Seed)} = []
227227
end
@@ -334,6 +334,7 @@ function mustBeValidMsgs(value)
334334

335335
function mustBeIntegerOrEmpty(value)
336336
if ~isempty(value)
337+
mustBeNumeric(value)
337338
mustBeInteger(value)
338339
end
339340
end

Diff for: openAIImages.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
arguments
4444
nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["dall-e-2", "dall-e-3"])} = "dall-e-2"
4545
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar}
46-
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 10
46+
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 10
4747
end
4848

4949
this.ModelName = nvp.ModelName;
@@ -83,7 +83,7 @@
8383
arguments
8484
this (1,1) openAIImages
8585
prompt {llms.utils.mustBeNonzeroLengthTextScalar}
86-
nvp.NumImages (1,1) {mustBePositive, mustBeInteger,...
86+
nvp.NumImages (1,1) {mustBeNumeric,mustBePositive,mustBeInteger,...
8787
mustBeLessThanOrEqual(nvp.NumImages,10)} = 1
8888
nvp.Size (1,1) string {mustBeMember(nvp.Size, ["256x256", "512x512", ...
8989
"1024x1024", "1792x1024", ...
@@ -174,7 +174,7 @@
174174
imagePath {mustBeValidFileType(imagePath)}
175175
prompt {llms.utils.mustBeNonzeroLengthTextScalar}
176176
nvp.MaskImagePath {mustBeValidFileType(nvp.MaskImagePath)}
177-
nvp.NumImages (1,1) {mustBePositive, mustBeInteger,...
177+
nvp.NumImages (1,1) {mustBeNumeric,mustBePositive,mustBeInteger,...
178178
mustBeLessThanOrEqual(nvp.NumImages,10)} = 1
179179
nvp.Size (1,1) string {mustBeMember(nvp.Size,...
180180
["256x256", "512x512","1024x1024"]), ...
@@ -235,7 +235,7 @@
235235
arguments
236236
this (1,1) openAIImages
237237
imagePath {mustBeValidFileType(imagePath)}
238-
nvp.NumImages (1,1) {mustBePositive, mustBeInteger,...
238+
nvp.NumImages (1,1) {mustBeNumeric,mustBePositive,mustBeInteger,...
239239
mustBeLessThanOrEqual(nvp.NumImages,10)} = 1
240240
nvp.Size (1,1) string {mustBeMember(nvp.Size,...
241241
["256x256", "512x512","1024x1024"]), ...

Diff for: tests/tazureChat.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ function deploymentNotFound(testCase)
336336
...
337337
"InvalidTimeOutType", struct( ...
338338
"Input",{{"TimeOut", "2" }},...
339-
"Error", "MATLAB:validators:mustBeReal"), ...
339+
"Error", "MATLAB:validators:mustBeNumeric"), ...
340340
...
341341
"InvalidTimeOutSize", struct( ...
342342
"Input",{{"TimeOut", [1 1 1] }},...
@@ -478,15 +478,15 @@ function deploymentNotFound(testCase)
478478
...
479479
"InvalidMaxNumTokensType",struct( ...
480480
"Input",{{ validMessages "MaxNumTokens" "2" }},...
481-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
481+
"Error","MATLAB:validators:mustBeNumeric"),...
482482
...
483483
"InvalidMaxNumTokensValue",struct( ...
484484
"Input",{{ validMessages "MaxNumTokens" 0 }},...
485485
"Error","MATLAB:validators:mustBePositive"),...
486486
...
487487
"InvalidNumCompletionsType",struct( ...
488488
"Input",{{ validMessages "NumCompletions" "2" }},...
489-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
489+
"Error","MATLAB:validators:mustBeNumeric"),...
490490
...
491491
"InvalidNumCompletionsValue",struct( ...
492492
"Input",{{ validMessages "NumCompletions" 0 }},...

Diff for: tests/textractOpenAIEmbeddings.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function testInvalidInputs(testCase, InvalidInput)
6969
...
7070
"InvalidTimeOutType", struct( ...
7171
"Input",{{ "bla", "TimeOut", "2" }},...
72-
"Error", "MATLAB:validators:mustBeReal"), ...
72+
"Error", "MATLAB:validators:mustBeNumeric"), ...
7373
...
7474
"InvalidTimeOutSize", struct( ...
7575
"Input",{{ "bla", "TimeOut", [1 1 1] }},...
@@ -93,11 +93,11 @@ function testInvalidInputs(testCase, InvalidInput)
9393
...
9494
"InvalidDimensionType",struct( ...
9595
"Input",{{"bla", "Dimensions", "123" }},...
96-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
96+
"Error","MATLAB:validators:mustBeNumeric"),...
9797
...
9898
"InvalidDimensionValue",struct( ...
9999
"Input",{{"bla", "Dimensions", "-11" }},...
100-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
100+
"Error","MATLAB:validators:mustBeNumeric"),...
101101
...
102102
"LargeDimensionValueForModelLarge",struct( ...
103103
"Input",{{"bla", "ModelName", "text-embedding-3-large", ...

Diff for: tests/tollamaChat.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ function queryModels(testCase)
322322
...
323323
"InvalidTimeOutType", struct( ...
324324
"Input",{{"TimeOut", "2" }},...
325-
"Error", "MATLAB:validators:mustBeReal"), ...
325+
"Error", "MATLAB:validators:mustBeNumeric"), ...
326326
...
327327
"InvalidTimeOutSize", struct( ...
328328
"Input",{{"TimeOut", [1 1 1] }},...
@@ -408,7 +408,7 @@ function queryModels(testCase)
408408
...
409409
"InvalidMaxNumTokensType",struct( ...
410410
"Input",{{ validMessages "MaxNumTokens" "2" }},...
411-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
411+
"Error","MATLAB:validators:mustBeNumeric"),...
412412
...
413413
"InvalidMaxNumTokensValue",struct( ...
414414
"Input",{{ validMessages "MaxNumTokens" 0 }},...

Diff for: tests/topenAIChat.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ function specialErrorForUnsupportedResponseFormat(testCase)
390390
...
391391
"InvalidTimeOutType", struct( ...
392392
"Input",{{"TimeOut", "2" }},...
393-
"Error", "MATLAB:validators:mustBeReal"), ...
393+
"Error", "MATLAB:validators:mustBeNumeric"), ...
394394
...
395395
"InvalidTimeOutSize", struct( ...
396396
"Input",{{"TimeOut", [1 1 1] }},...
@@ -535,15 +535,15 @@ function specialErrorForUnsupportedResponseFormat(testCase)
535535
...
536536
"InvalidMaxNumTokensType",struct( ...
537537
"Input",{{ validMessages "MaxNumTokens" "2" }},...
538-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
538+
"Error","MATLAB:validators:mustBeNumeric"),...
539539
...
540540
"InvalidMaxNumTokensValue",struct( ...
541541
"Input",{{ validMessages "MaxNumTokens" 0 }},...
542542
"Error","MATLAB:validators:mustBePositive"),...
543543
...
544544
"InvalidNumCompletionsType",struct( ...
545545
"Input",{{ validMessages "NumCompletions" "2" }},...
546-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
546+
"Error","MATLAB:validators:mustBeNumeric"),...
547547
...
548548
"InvalidNumCompletionsValue",struct( ...
549549
"Input",{{ validMessages "NumCompletions" 0 }},...
@@ -563,5 +563,5 @@ function specialErrorForUnsupportedResponseFormat(testCase)
563563
...
564564
"InvalidSeed",struct( ...
565565
"Input",{{ validMessages "Seed" "2" }},...
566-
"Error","MATLAB:validators:mustBeNumericOrLogical"));
566+
"Error","MATLAB:validators:mustBeNumeric"));
567567
end

Diff for: tests/topenAIImages.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function testThatImageIsReturned(testCase)
143143
invalidConstructorInput = struct( ...
144144
"InvalidTimeOutType", struct( ...
145145
"Input",{{"TimeOut", "2" }},...
146-
"Error", "MATLAB:validators:mustBeReal"), ...
146+
"Error", "MATLAB:validators:mustBeNumeric"), ...
147147
...
148148
"InvalidTimeOutSize", struct( ...
149149
"Input",{{"TimeOut", [1 1 1] }},...
@@ -182,7 +182,7 @@ function testThatImageIsReturned(testCase)
182182
...
183183
"InvalidNumImagesType",struct( ...
184184
"Input",{{ "prompt" "NumImages" "2" }},...
185-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
185+
"Error","MATLAB:validators:mustBeNumeric"),...
186186
...
187187
"LargeValueForNumImages",struct( ...
188188
"Input",{{ "prompt", "NumImages", 20 }},...
@@ -227,7 +227,7 @@ function testThatImageIsReturned(testCase)
227227
...
228228
"InvalidNumImagesType",struct( ...
229229
"Input",{{ validImage,"NumImages", "2" }},...
230-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
230+
"Error","MATLAB:validators:mustBeNumeric"),...
231231
...
232232
"LargeValueForNumImages",struct( ...
233233
"Input",{{ validImage, "NumImages", 20 }},...
@@ -276,7 +276,7 @@ function testThatImageIsReturned(testCase)
276276
...
277277
"InvalidNumImagesType",struct( ...
278278
"Input",{{ validImage,"prompt", "NumImages", "2" }},...
279-
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
279+
"Error","MATLAB:validators:mustBeNumeric"),...
280280
...
281281
"LargeValueForNumImages",struct( ...
282282
"Input",{{ validImage, "prompt", "NumImages", 20 }},...

0 commit comments

Comments
 (0)