Skip to content

Commit

Permalink
More specific error messages: “numeric,” not “numeric or logical”
Browse files Browse the repository at this point in the history
  • Loading branch information
ccreutzi committed Dec 18, 2024
1 parent 25b8ffc commit 70baea5
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 39 deletions.
9 changes: 5 additions & 4 deletions azureChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
nvp.ResponseFormat {llms.utils.mustBeResponseFormat} = "text"
nvp.PresencePenalty {llms.utils.mustBeValidPenalty} = 0
nvp.FrequencyPenalty {llms.utils.mustBeValidPenalty} = 0
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 10
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 10
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
end

Expand Down Expand Up @@ -225,10 +225,10 @@
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar} = this.APIKey
nvp.PresencePenalty {llms.utils.mustBeValidPenalty} = this.PresencePenalty
nvp.FrequencyPenalty {llms.utils.mustBeValidPenalty} = this.FrequencyPenalty
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = this.TimeOut
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = this.TimeOut
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
nvp.NumCompletions (1,1) {mustBePositive, mustBeInteger} = 1
nvp.MaxNumTokens (1,1) {mustBePositive} = inf
nvp.NumCompletions (1,1) {mustBeNumeric,mustBePositive, mustBeInteger} = 1
nvp.MaxNumTokens (1,1) {mustBeNumeric,mustBePositive} = inf
nvp.ToolChoice {mustBeValidFunctionCall(this, nvp.ToolChoice)} = []
nvp.Seed {mustBeIntegerOrEmpty(nvp.Seed)} = []
end
Expand Down Expand Up @@ -353,6 +353,7 @@ function mustBeValidMsgs(value)

function mustBeIntegerOrEmpty(value)
if ~isempty(value)
mustBeNumeric(value)
mustBeInteger(value)
end
end
Expand Down
5 changes: 3 additions & 2 deletions extractOpenAIEmbeddings.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
text (1,:) {mustBeNonzeroLengthText}
nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["text-embedding-ada-002", ...
"text-embedding-3-large", "text-embedding-3-small"])} = "text-embedding-ada-002"
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 10
nvp.Dimensions (1,1) {mustBeInteger,mustBePositive}
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 10
nvp.Dimensions (1,1) {mustBeNumeric,mustBeInteger,mustBePositive}
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar}
end

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

mustBeNumeric(dimensions);
if dimensions>model2dim(modelName)
error("llms:dimensionsMustBeSmallerThan", ...
llms.utils.errorMessageCatalog.getMessage("llms:dimensionsMustBeSmallerThan", ...
Expand Down
2 changes: 1 addition & 1 deletion messageHistory.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@

arguments
this (1,1) messageHistory
idx (1,1) {mustBeInteger, mustBePositive}
idx (1,1) {mustBeNumeric,mustBeInteger,mustBePositive}
end
if isempty(this.Messages)
error("llms:removeFromEmptyHistory",llms.utils.errorMessageCatalog.getMessage("llms:removeFromEmptyHistory"));
Expand Down
17 changes: 9 additions & 8 deletions ollamaChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
properties
ModelName (1,1) string
Endpoint (1,1) string
TopK (1,1) {mustBeReal,mustBePositive} = Inf
TopK (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = Inf
MinP (1,1) {llms.utils.mustBeValidProbability} = 0
TailFreeSamplingZ (1,1) {mustBeReal} = 1
TailFreeSamplingZ (1,1) {mustBeNumeric,mustBeReal} = 1
end

methods
Expand All @@ -87,8 +87,8 @@
nvp.TopK (1,1) {mustBeReal,mustBePositive} = Inf
nvp.StopSequences {llms.utils.mustBeValidStop} = {}
nvp.ResponseFormat (1,1) string {mustBeMember(nvp.ResponseFormat,["text","json"])} = "text"
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 120
nvp.TailFreeSamplingZ (1,1) {mustBeReal} = 1
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 120
nvp.TailFreeSamplingZ (1,1) {mustBeNumeric,mustBeReal} = 1
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
nvp.Endpoint (1,1) string = "127.0.0.1:11434"
end
Expand Down Expand Up @@ -190,14 +190,14 @@
nvp.Temperature {llms.utils.mustBeValidTemperature} = this.Temperature
nvp.TopP {llms.utils.mustBeValidProbability} = this.TopP
nvp.MinP {llms.utils.mustBeValidProbability} = this.MinP
nvp.TopK (1,1) {mustBeReal,mustBePositive} = this.TopK
nvp.TopK (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = this.TopK
nvp.StopSequences {llms.utils.mustBeValidStop} = this.StopSequences
nvp.ResponseFormat {llms.utils.mustBeResponseFormat} = this.ResponseFormat
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = this.TimeOut
nvp.TailFreeSamplingZ (1,1) {mustBeReal} = this.TailFreeSamplingZ
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = this.TimeOut
nvp.TailFreeSamplingZ (1,1) {mustBeNumeric,mustBeReal} = this.TailFreeSamplingZ
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
nvp.Endpoint (1,1) string = this.Endpoint
nvp.MaxNumTokens (1,1) {mustBePositive} = inf
nvp.MaxNumTokens (1,1) {mustBeNumeric,mustBePositive} = inf
nvp.Seed {mustBeIntegerOrEmpty(nvp.Seed)} = []
end

Expand Down Expand Up @@ -313,6 +313,7 @@ function mustBeValidMsgs(value)

function mustBeIntegerOrEmpty(value)
if ~isempty(value)
mustBeNumeric(value)
mustBeInteger(value)
end
end
Expand Down
9 changes: 5 additions & 4 deletions openAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar}
nvp.PresencePenalty {llms.utils.mustBeValidPenalty} = 0
nvp.FrequencyPenalty {llms.utils.mustBeValidPenalty} = 0
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 10
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 10
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
end

Expand Down Expand Up @@ -218,10 +218,10 @@
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar} = this.APIKey
nvp.PresencePenalty {llms.utils.mustBeValidPenalty} = this.PresencePenalty
nvp.FrequencyPenalty {llms.utils.mustBeValidPenalty} = this.FrequencyPenalty
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = this.TimeOut
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = this.TimeOut
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
nvp.NumCompletions (1,1) {mustBePositive, mustBeInteger} = 1
nvp.MaxNumTokens (1,1) {mustBePositive} = inf
nvp.NumCompletions (1,1) {mustBeNumeric,mustBePositive, mustBeInteger} = 1
nvp.MaxNumTokens (1,1) {mustBeNumeric,mustBePositive} = inf
nvp.ToolChoice {mustBeValidFunctionCall(this, nvp.ToolChoice)} = []
nvp.Seed {mustBeIntegerOrEmpty(nvp.Seed)} = []
end
Expand Down Expand Up @@ -334,6 +334,7 @@ function mustBeValidMsgs(value)

function mustBeIntegerOrEmpty(value)
if ~isempty(value)
mustBeNumeric(value)
mustBeInteger(value)
end
end
Expand Down
8 changes: 4 additions & 4 deletions openAIImages.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
arguments
nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["dall-e-2", "dall-e-3"])} = "dall-e-2"
nvp.APIKey {llms.utils.mustBeNonzeroLengthTextScalar}
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 10
nvp.TimeOut (1,1) {mustBeNumeric,mustBeReal,mustBePositive} = 10
end

this.ModelName = nvp.ModelName;
Expand Down Expand Up @@ -83,7 +83,7 @@
arguments
this (1,1) openAIImages
prompt {llms.utils.mustBeNonzeroLengthTextScalar}
nvp.NumImages (1,1) {mustBePositive, mustBeInteger,...
nvp.NumImages (1,1) {mustBeNumeric,mustBePositive,mustBeInteger,...
mustBeLessThanOrEqual(nvp.NumImages,10)} = 1
nvp.Size (1,1) string {mustBeMember(nvp.Size, ["256x256", "512x512", ...
"1024x1024", "1792x1024", ...
Expand Down Expand Up @@ -174,7 +174,7 @@
imagePath {mustBeValidFileType(imagePath)}
prompt {llms.utils.mustBeNonzeroLengthTextScalar}
nvp.MaskImagePath {mustBeValidFileType(nvp.MaskImagePath)}
nvp.NumImages (1,1) {mustBePositive, mustBeInteger,...
nvp.NumImages (1,1) {mustBeNumeric,mustBePositive,mustBeInteger,...
mustBeLessThanOrEqual(nvp.NumImages,10)} = 1
nvp.Size (1,1) string {mustBeMember(nvp.Size,...
["256x256", "512x512","1024x1024"]), ...
Expand Down Expand Up @@ -235,7 +235,7 @@
arguments
this (1,1) openAIImages
imagePath {mustBeValidFileType(imagePath)}
nvp.NumImages (1,1) {mustBePositive, mustBeInteger,...
nvp.NumImages (1,1) {mustBeNumeric,mustBePositive,mustBeInteger,...
mustBeLessThanOrEqual(nvp.NumImages,10)} = 1
nvp.Size (1,1) string {mustBeMember(nvp.Size,...
["256x256", "512x512","1024x1024"]), ...
Expand Down
6 changes: 3 additions & 3 deletions tests/tazureChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function deploymentNotFound(testCase)
...
"InvalidTimeOutType", struct( ...
"Input",{{"TimeOut", "2" }},...
"Error", "MATLAB:validators:mustBeReal"), ...
"Error", "MATLAB:validators:mustBeNumeric"), ...
...
"InvalidTimeOutSize", struct( ...
"Input",{{"TimeOut", [1 1 1] }},...
Expand Down Expand Up @@ -478,15 +478,15 @@ function deploymentNotFound(testCase)
...
"InvalidMaxNumTokensType",struct( ...
"Input",{{ validMessages "MaxNumTokens" "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"InvalidMaxNumTokensValue",struct( ...
"Input",{{ validMessages "MaxNumTokens" 0 }},...
"Error","MATLAB:validators:mustBePositive"),...
...
"InvalidNumCompletionsType",struct( ...
"Input",{{ validMessages "NumCompletions" "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"InvalidNumCompletionsValue",struct( ...
"Input",{{ validMessages "NumCompletions" 0 }},...
Expand Down
6 changes: 3 additions & 3 deletions tests/textractOpenAIEmbeddings.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function testInvalidInputs(testCase, InvalidInput)
...
"InvalidTimeOutType", struct( ...
"Input",{{ "bla", "TimeOut", "2" }},...
"Error", "MATLAB:validators:mustBeReal"), ...
"Error", "MATLAB:validators:mustBeNumeric"), ...
...
"InvalidTimeOutSize", struct( ...
"Input",{{ "bla", "TimeOut", [1 1 1] }},...
Expand All @@ -93,11 +93,11 @@ function testInvalidInputs(testCase, InvalidInput)
...
"InvalidDimensionType",struct( ...
"Input",{{"bla", "Dimensions", "123" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"InvalidDimensionValue",struct( ...
"Input",{{"bla", "Dimensions", "-11" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"LargeDimensionValueForModelLarge",struct( ...
"Input",{{"bla", "ModelName", "text-embedding-3-large", ...
Expand Down
4 changes: 2 additions & 2 deletions tests/tollamaChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function queryModels(testCase)
...
"InvalidTimeOutType", struct( ...
"Input",{{"TimeOut", "2" }},...
"Error", "MATLAB:validators:mustBeReal"), ...
"Error", "MATLAB:validators:mustBeNumeric"), ...
...
"InvalidTimeOutSize", struct( ...
"Input",{{"TimeOut", [1 1 1] }},...
Expand Down Expand Up @@ -408,7 +408,7 @@ function queryModels(testCase)
...
"InvalidMaxNumTokensType",struct( ...
"Input",{{ validMessages "MaxNumTokens" "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"InvalidMaxNumTokensValue",struct( ...
"Input",{{ validMessages "MaxNumTokens" 0 }},...
Expand Down
8 changes: 4 additions & 4 deletions tests/topenAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ function specialErrorForUnsupportedResponseFormat(testCase)
...
"InvalidTimeOutType", struct( ...
"Input",{{"TimeOut", "2" }},...
"Error", "MATLAB:validators:mustBeReal"), ...
"Error", "MATLAB:validators:mustBeNumeric"), ...
...
"InvalidTimeOutSize", struct( ...
"Input",{{"TimeOut", [1 1 1] }},...
Expand Down Expand Up @@ -535,15 +535,15 @@ function specialErrorForUnsupportedResponseFormat(testCase)
...
"InvalidMaxNumTokensType",struct( ...
"Input",{{ validMessages "MaxNumTokens" "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"InvalidMaxNumTokensValue",struct( ...
"Input",{{ validMessages "MaxNumTokens" 0 }},...
"Error","MATLAB:validators:mustBePositive"),...
...
"InvalidNumCompletionsType",struct( ...
"Input",{{ validMessages "NumCompletions" "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"InvalidNumCompletionsValue",struct( ...
"Input",{{ validMessages "NumCompletions" 0 }},...
Expand All @@ -563,5 +563,5 @@ function specialErrorForUnsupportedResponseFormat(testCase)
...
"InvalidSeed",struct( ...
"Input",{{ validMessages "Seed" "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"));
"Error","MATLAB:validators:mustBeNumeric"));
end
8 changes: 4 additions & 4 deletions tests/topenAIImages.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function testThatImageIsReturned(testCase)
invalidConstructorInput = struct( ...
"InvalidTimeOutType", struct( ...
"Input",{{"TimeOut", "2" }},...
"Error", "MATLAB:validators:mustBeReal"), ...
"Error", "MATLAB:validators:mustBeNumeric"), ...
...
"InvalidTimeOutSize", struct( ...
"Input",{{"TimeOut", [1 1 1] }},...
Expand Down Expand Up @@ -182,7 +182,7 @@ function testThatImageIsReturned(testCase)
...
"InvalidNumImagesType",struct( ...
"Input",{{ "prompt" "NumImages" "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"LargeValueForNumImages",struct( ...
"Input",{{ "prompt", "NumImages", 20 }},...
Expand Down Expand Up @@ -227,7 +227,7 @@ function testThatImageIsReturned(testCase)
...
"InvalidNumImagesType",struct( ...
"Input",{{ validImage,"NumImages", "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"LargeValueForNumImages",struct( ...
"Input",{{ validImage, "NumImages", 20 }},...
Expand Down Expand Up @@ -276,7 +276,7 @@ function testThatImageIsReturned(testCase)
...
"InvalidNumImagesType",struct( ...
"Input",{{ validImage,"prompt", "NumImages", "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
"Error","MATLAB:validators:mustBeNumeric"),...
...
"LargeValueForNumImages",struct( ...
"Input",{{ validImage, "prompt", "NumImages", 20 }},...
Expand Down

0 comments on commit 70baea5

Please sign in to comment.