Skip to content

Commit

Permalink
Update topenAIChat.m
Browse files Browse the repository at this point in the history
  • Loading branch information
vpapanasta committed Apr 24, 2024
1 parent a62530b commit 751b348
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions tests/topenAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function saveEnvVar(testCase)
end

properties(TestParameter)
InvalidConstructorInput = iGetInvalidConstructorInput;
InvalidGenerateInput = iGetInvalidGenerateInput;
InvalidValuesSetters = iGetInvalidValuesSetters;
InvalidConstructorInput = iGetInvalidConstructorInput();
InvalidGenerateInput = iGetInvalidGenerateInput();
InvalidValuesSetters = iGetInvalidValuesSetters();
end

methods(Test)
Expand All @@ -37,10 +37,6 @@ function generateAcceptsMessagesAsInput(testCase)
testCase.verifyWarningFree(@()generate(chat,messages));
end

function constructMdlWithInvalidParameters(testCase)
testCase.verifyError(@()openAIChat(ApiKey="this-is-not-a-real-key", ModelName="gpt-4", ResponseFormat="json"), "llms:invalidOptionAndValueForModel");
end

function keyNotFound(testCase)
testCase.verifyError(@()openAIChat, "llms:keyMustBeSpecified");
end
Expand Down Expand Up @@ -115,15 +111,21 @@ function noStopSequencesNoMaxNumTokens(testCase)
testCase.verifyWarningFree(@()generate(chat,"This is okay"));
end

function createOpenAIChatWithStreamFunc(testCase)
sf = @(x)fprintf("%s", x);
chat = openAIChat(ApiKey="this-is-not-a-real-key", StreamFun=sf);
testCase.verifyWarningFree(@()generate(chat, "Hello world."));
end

function createOpenAIChatWithOpenAIKey(testCase)
chat = openAIChat(ApiKey=getenv("OPENAI_KEY"));
testCase.verifyWarningFree(@()generate(chat,"Hello world."));
testCase.verifyWarningFree(@()generate(chat, "Hello world."));
end

end
end

function invalidValuesSetters = iGetInvalidValuesSetters
function invalidValuesSetters = iGetInvalidValuesSetters()

invalidValuesSetters = struct( ...
"InvalidTemperatureType", struct( ...
Expand Down Expand Up @@ -227,7 +229,7 @@ function createOpenAIChatWithOpenAIKey(testCase)
"Error", "MATLAB:notGreaterEqual"));
end

function invalidConstructorInput = iGetInvalidConstructorInput
function invalidConstructorInput = iGetInvalidConstructorInput()
validFunction = openAIFunction("funName");
invalidConstructorInput = struct( ...
"InvalidResponseFormatValue", struct( ...
Expand All @@ -238,6 +240,10 @@ function createOpenAIChatWithOpenAIKey(testCase)
"Input",{{"ResponseFormat", ["text" "text"] }},...
"Error", "MATLAB:validation:IncompatibleSize"), ...
...
"InvalidResponseFormatModelCombination", struct( ...
"Input", {{"ApiKey", "this-is-not-a-real-key", "ModelName", "gpt-4", "ResponseFormat", "json"}}, ...
"Error", "llms:invalidOptionAndValueForModel"), ...
...
"InvalidStreamFunType", struct( ...
"Input",{{"StreamFun", "2" }},...
"Error", "MATLAB:validators:mustBeA"), ...
Expand Down Expand Up @@ -371,7 +377,7 @@ function createOpenAIChatWithOpenAIKey(testCase)
"Error","MATLAB:validators:mustBeTextScalar"));
end

function invalidGenerateInput = iGetInvalidGenerateInput
function invalidGenerateInput = iGetInvalidGenerateInput()
emptyMessages = openAIMessages;
validMessages = addUserMessage(emptyMessages,"Who invented the telephone?");

Expand Down

0 comments on commit 751b348

Please sign in to comment.