Skip to content
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

Fix parallel calls #22

Merged
merged 4 commits into from
Apr 24, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ To learn how to use this in your workflows, see [Examples](/examples/).
- [SummarizeLargeDocumentsUsingChatGPTandMATLAB.mlx](/examples/SummarizeLargeDocumentsUsingChatGPTandMATLAB.mlx): Learn to create concise summaries of long texts with ChatGPT. (Requires Text Analytics Toolbox™)
- [CreateSimpleChatBot.mlx](/examples/CreateSimpleChatBot.mlx): Build a conversational chatbot capable of handling various dialogue scenarios using ChatGPT. (Requires Text Analytics Toolbox)
- [AnalyzeScientificPapersUsingFunctionCalls.mlx](/examples/AnalyzeScientificPapersUsingFunctionCalls.mlx): Learn how to create agents capable of executing MATLAB functions.
- [ExampleParallelFunctionCalls.mlx](/examples/ExampleParallelFunctionCalls.mlx): Learn how to take advantage of parallel function calling.
- [AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.mlx](/examples/AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.mlx): Learn how to take advantage of parallel function calling.
- [RetrievalAugmentedGenerationUsingChatGPTandMATLAB.mlx](/examples/RetrievalAugmentedGenerationUsingChatGPTandMATLAB.mlx): Learn about retrieval augmented generation with a simple use case. (Requires Text Analytics Toolbox™)
- [DescribeImagesUsingChatGPT.mlx](/examples/DescribeImagesUsingChatGPT.mlx): Learn how to use GPT-4 Turbo with Vision to understand the content of an image.
- [AnalyzeSentimentinTextUsingChatGPTinJSONMode.mlx](/examples/AnalyzeSentimentinTextUsingChatGPTinJSONMode.mlx): Learn how to use JSON mode in chat completions
Expand Down
debymf marked this conversation as resolved.
Show resolved Hide resolved
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
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")
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