Skip to content

Commit 2e8a540

Browse files
committed
Fix argument validation for extractOpenAIEmbeddings
1 parent d3e7389 commit 2e8a540

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

extractOpenAIEmbeddings.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
% [emb, response] = EXTRACTOPENAIEMBEDDINGS(...) also returns the full
2121
% response from the OpenAI API call.
2222
%
23-
% Copyright 2023 The MathWorks, Inc.
23+
% Copyright 2023-2024 The MathWorks, Inc.
2424

2525
arguments
26-
text (1,:) {mustBeText}
26+
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"
2929
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 10
30-
nvp.Dimensions (1,1) {mustBeInteger}
30+
nvp.Dimensions (1,1) {mustBeInteger,mustBePositive, mustBeLessThanOrEqual(nvp.Dimensions, 1536)}
3131
nvp.ApiKey {llms.utils.mustBeNonzeroLengthTextScalar}
3232
end
3333

tests/textractOpenAIEmbeddings.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ function testInvalidInputs(testCase, InvalidInput)
5656

5757
function invalidInput = iGetInvalidInput
5858
invalidInput = struct( ...
59+
"InvalidEmptyText", struct( ...
60+
"Input",{{ "" }},...
61+
"Error", "MATLAB:validators:mustBeNonzeroLengthText"), ...
62+
...
63+
"InvalidEmptyTextArray", struct( ...
64+
"Input",{{ ["", ""] }},...
65+
"Error", "MATLAB:validators:mustBeNonzeroLengthText"), ...
66+
...
5967
"InvalidTimeOutType", struct( ...
6068
"Input",{{ "bla", "TimeOut", "2" }},...
6169
"Error", "MATLAB:validators:mustBeReal"), ...
@@ -66,7 +74,7 @@ function testInvalidInputs(testCase, InvalidInput)
6674
...
6775
"WrongTypeText",struct( ...
6876
"Input",{{ 123 }},...
69-
"Error","MATLAB:validators:mustBeText"),...
77+
"Error","MATLAB:validators:mustBeNonzeroLengthText"),...
7078
...
7179
"InvalidModelNameType",struct( ...
7280
"Input",{{"bla", "ModelName", 0 }},...
@@ -84,6 +92,14 @@ function testInvalidInputs(testCase, InvalidInput)
8492
"Input",{{"bla", "Dimensions", "123" }},...
8593
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
8694
...
95+
"InvalidDimensionValue",struct( ...
96+
"Input",{{"bla", "Dimensions", "-11" }},...
97+
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
98+
...
99+
"LargeDimensionValue",struct( ...
100+
"Input",{{"bla", "Dimensions", 100000 }},...
101+
"Error","MATLAB:validators:mustBeLessThanOrEqual"),...
102+
...
87103
"InvalidDimensionSize",struct( ...
88104
"Input",{{"bla", "Dimensions", [123, 123] }},...
89105
"Error","MATLAB:validation:IncompatibleSize"),...

0 commit comments

Comments
 (0)