@@ -16,9 +16,9 @@ function saveEnvVar(testCase)
1616 end
1717
1818 properties (TestParameter )
19- InvalidConstructorInput = iGetInvalidConstructorInput;
20- InvalidGenerateInput = iGetInvalidGenerateInput;
21- InvalidValuesSetters = iGetInvalidValuesSetters;
19+ InvalidConstructorInput = iGetInvalidConstructorInput() ;
20+ InvalidGenerateInput = iGetInvalidGenerateInput() ;
21+ InvalidValuesSetters = iGetInvalidValuesSetters() ;
2222 end
2323
2424 methods (Test )
@@ -37,10 +37,6 @@ function generateAcceptsMessagesAsInput(testCase)
3737 testCase .verifyWarningFree(@()generate(chat ,messages ));
3838 end
3939
40- function constructMdlWithInvalidParameters(testCase )
41- testCase .verifyError(@()openAIChat(ApiKey = " this-is-not-a-real-key" , ModelName= " gpt-4" , ResponseFormat= " json" ), " llms:invalidOptionAndValueForModel" );
42- end
43-
4440 function keyNotFound(testCase )
4541 testCase .verifyError(@()openAIChat , " llms:keyMustBeSpecified" );
4642 end
@@ -115,15 +111,21 @@ function noStopSequencesNoMaxNumTokens(testCase)
115111 testCase .verifyWarningFree(@()generate(chat ," This is okay" ));
116112 end
117113
114+ function createOpenAIChatWithStreamFunc(testCase )
115+ sf = @(x )fprintf(" %s" , x );
116+ chat = openAIChat(ApiKey = " this-is-not-a-real-key" , StreamFun= sf );
117+ testCase .verifyWarningFree(@()generate(chat , " Hello world." ));
118+ end
119+
118120 function createOpenAIChatWithOpenAIKey(testCase )
119121 chat = openAIChat(ApiKey = getenv(" OPENAI_KEY" ));
120- testCase .verifyWarningFree(@()generate(chat ," Hello world." ));
122+ testCase .verifyWarningFree(@()generate(chat , " Hello world." ));
121123 end
122124
123125 end
124126end
125127
126- function invalidValuesSetters = iGetInvalidValuesSetters
128+ function invalidValuesSetters = iGetInvalidValuesSetters()
127129
128130invalidValuesSetters = struct( ...
129131 " InvalidTemperatureType" , struct( ...
@@ -227,7 +229,7 @@ function createOpenAIChatWithOpenAIKey(testCase)
227229 " Error" , " MATLAB:notGreaterEqual" ));
228230end
229231
230- function invalidConstructorInput = iGetInvalidConstructorInput
232+ function invalidConstructorInput = iGetInvalidConstructorInput()
231233validFunction = openAIFunction(" funName" );
232234invalidConstructorInput = struct( ...
233235 " InvalidResponseFormatValue" , struct( ...
@@ -238,6 +240,10 @@ function createOpenAIChatWithOpenAIKey(testCase)
238240 " Input" ,{{" ResponseFormat" , [" text" " text" ] }},...
239241 " Error" , " MATLAB:validation:IncompatibleSize" ), ...
240242 ...
243+ " InvalidResponseFormatModelCombination" , struct( ...
244+ " Input" , {{" ApiKey" , " this-is-not-a-real-key" , " ModelName" , " gpt-4" , " ResponseFormat" , " json" }}, ...
245+ " Error" , " llms:invalidOptionAndValueForModel" ), ...
246+ ...
241247 " InvalidStreamFunType" , struct( ...
242248 " Input" ,{{" StreamFun" , " 2" }},...
243249 " Error" , " MATLAB:validators:mustBeA" ), ...
@@ -371,7 +377,7 @@ function createOpenAIChatWithOpenAIKey(testCase)
371377 " Error" ," MATLAB:validators:mustBeTextScalar" ));
372378end
373379
374- function invalidGenerateInput = iGetInvalidGenerateInput
380+ function invalidGenerateInput = iGetInvalidGenerateInput()
375381emptyMessages = openAIMessages ;
376382validMessages = addUserMessage(emptyMessages ," Who invented the telephone?" );
377383
0 commit comments