Skip to content

Fix function call #23

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 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file modified examples/AnalyzeScientificPapersUsingFunctionCalls.mlx
Binary file not shown.
Binary file not shown.
Binary file removed examples/ExampleParallelFunctionCalls.mlx
Binary file not shown.
8 changes: 5 additions & 3 deletions openAIImages.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

arguments
this (1,1) openAIImages
Copy link
Member

Choose a reason for hiding this comment

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

openAIImages is not perfectly aligned. Just delete a space before it.

prompt {mustBeTextScalar}
prompt {mustBeNonzeroLengthTextScalar}
nvp.NumImages (1,1) {mustBePositive, mustBeInteger,...
mustBeLessThanOrEqual(nvp.NumImages,10)} = 1
nvp.Size (1,1) string {mustBeMember(nvp.Size, ["256x256", "512x512", ...
Expand Down Expand Up @@ -176,7 +176,7 @@
arguments
this (1,1) openAIImages
imagePath {mustBeValidFileType(imagePath)}
prompt {mustBeTextScalar}
prompt {mustBeNonzeroLengthTextScalar}
nvp.MaskImagePath {mustBeValidFileType(nvp.MaskImagePath)}
nvp.NumImages (1,1) {mustBePositive, mustBeInteger,...
mustBeLessThanOrEqual(nvp.NumImages,10)} = 1
Expand Down Expand Up @@ -345,7 +345,9 @@ function validatePromptSize(model, prompt)
function mustBeValidFileType(filePath)
mustBeFile(filePath);
s = dir(filePath);
if ~endsWith(s.name, ".png")
imgDetails = imfinfo(filePath);
imgFormat = imgDetails.Format;
if ~(imgFormat=="png")
Copy link
Member

Choose a reason for hiding this comment

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

How come do we accept only "png"? Is it a requirement from the OpenAI API?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that restriction comes from the OpenAI side. We might later want to add a test to make sure this behavior not changing.

error("llms:pngExpected", ...
llms.utils.errorMessageCatalog.getMessage("llms:pngExpected"));
end
Expand Down
Binary file added tests/test_files/solar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 18 additions & 4 deletions tests/topenAIImages.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ function constructModelWithAllNVP(testCase)
testCase.verifyEqual(mdl.ModelName, modelName);
end

function fakePNGImage(testCase)
mdl = openAIImages(ApiKey="this-is-not-a-real-key");
fakePng = fullfile("test_files", "solar.png");
testCase.verifyError(@()edit(mdl,fakePng, "bla"), "llms:pngExpected");
end

function invalidInputsConstructor(testCase, InvalidConstructorInput)
testCase.verifyError(@()openAIImages(InvalidConstructorInput.Input{:}), InvalidConstructorInput.Error);
end
Expand Down Expand Up @@ -157,11 +163,15 @@ function invalidInputsVariation(testCase, InvalidVariationInput)
invalidGenerateInput = struct( ...
"EmptyInput",struct( ...
"Input",{{ [] }},...
"Error","MATLAB:validators:mustBeTextScalar"),...
"Error","MATLAB:validators:mustBeNonzeroLengthText"),...
...
"InvalidInputType",struct( ...
"Input",{{ 123 }},...
"Error","MATLAB:validators:mustBeTextScalar"),...
"Error","MATLAB:validators:mustBeNonzeroLengthText"),...
...
"InvalidPromptLen",struct( ...
"Input",{{ "" }},...
"Error","MATLAB:validators:mustBeNonzeroLengthText"),...
...
"InvalidNumImagesType",struct( ...
"Input",{{ "prompt" "NumImages" "2" }},...
Expand Down Expand Up @@ -233,17 +243,21 @@ function invalidInputsVariation(testCase, InvalidVariationInput)
"Input",{{ 123, "prompt" }},...
"Error","MATLAB:validators:mustBeNonzeroLengthText"),...
...
"InvalidPromptLen",struct( ...
"Input",{{ validImage, "" }},...
"Error","MATLAB:validators:mustBeNonzeroLengthText"),...
...
"InvalidImageExtension",struct( ...
"Input",{{ nonPNGImage, "prompt" }},...
"Error","llms:pngExpected"),...
...
"EmptyPrompt",struct( ...
"Input",{{ validImage, [] }},...
"Error","MATLAB:validators:mustBeTextScalar"),...
"Error","MATLAB:validators:mustBeNonzeroLengthText"),...
...
"InvalidPromptType",struct( ...
"Input",{{ validImage, 123 }},...
"Error","MATLAB:validators:mustBeTextScalar"),...
"Error","MATLAB:validators:mustBeNonzeroLengthText"),...
...
"InvalidMaskImage",struct( ...
"Input",{{ validImage, "foo", "MaskImagePath", 123 }},...
Expand Down
Loading