Skip to content

Fix argument validation for extractOpenAIEmbeddings #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions extractOpenAIEmbeddings.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
% [emb, response] = EXTRACTOPENAIEMBEDDINGS(...) also returns the full
% response from the OpenAI API call.
%
% Copyright 2023 The MathWorks, Inc.
% Copyright 2023-2024 The MathWorks, Inc.

arguments
text (1,:) {mustBeText}
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}
nvp.Dimensions (1,1) {mustBeInteger,mustBePositive, mustBeLessThanOrEqual(nvp.Dimensions, 1536)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need mustBeReal as well or is it covered by mustBeInteger? It's worth checking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 1536 the upper limit for all accepted models?

nvp.ApiKey {llms.utils.mustBeNonzeroLengthTextScalar}
end

Expand Down
18 changes: 17 additions & 1 deletion tests/textractOpenAIEmbeddings.m
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% Copyright 2023-2024 The MathWorks, Inc.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ function testInvalidInputs(testCase, InvalidInput)

function invalidInput = iGetInvalidInput
invalidInput = struct( ...
"InvalidEmptyText", struct( ...
"Input",{{ "" }},...
"Error", "MATLAB:validators:mustBeNonzeroLengthText"), ...
...
"InvalidEmptyTextArray", struct( ...
"Input",{{ ["", ""] }},...
"Error", "MATLAB:validators:mustBeNonzeroLengthText"), ...
...
"InvalidTimeOutType", struct( ...
"Input",{{ "bla", "TimeOut", "2" }},...
"Error", "MATLAB:validators:mustBeReal"), ...
Expand All @@ -66,7 +74,7 @@ function testInvalidInputs(testCase, InvalidInput)
...
"WrongTypeText",struct( ...
"Input",{{ 123 }},...
"Error","MATLAB:validators:mustBeText"),...
"Error","MATLAB:validators:mustBeNonzeroLengthText"),...
...
"InvalidModelNameType",struct( ...
"Input",{{"bla", "ModelName", 0 }},...
Expand All @@ -84,6 +92,14 @@ function testInvalidInputs(testCase, InvalidInput)
"Input",{{"bla", "Dimensions", "123" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
...
"InvalidDimensionValue",struct( ...
"Input",{{"bla", "Dimensions", "-11" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"),...
...
"LargeDimensionValue",struct( ...
"Input",{{"bla", "Dimensions", 100000 }},...
"Error","MATLAB:validators:mustBeLessThanOrEqual"),...
...
"InvalidDimensionSize",struct( ...
"Input",{{"bla", "Dimensions", [123, 123] }},...
"Error","MATLAB:validation:IncompatibleSize"),...
Expand Down
Loading