diff --git a/tests/topenAIChat.m b/tests/topenAIChat.m index 5f9a41c..904a206 100644 --- a/tests/topenAIChat.m +++ b/tests/topenAIChat.m @@ -126,10 +126,23 @@ function noStopSequencesNoMaxNumTokens(testCase) end function createOpenAIChatWithStreamFunc(testCase) - sf = @(x)fprintf("%s", x); - chat = openAIChat(ApiKey="this-is-not-a-real-key", StreamFun=sf); + + function seen = sf(str) + persistent data; + if isempty(data) + data = strings(1, 0); + end + % Append streamed text to an empty string array of length 1 + data = [data, str]; + seen = data; + end + chat = openAIChat(ApiKey=getenv("OPENAI_KEY"), StreamFun=@sf); testCase.verifyWarningFree(@()generate(chat, "Hello world.")); + % Checking that persistent data, which is still stored in + % memory, is greater than 1. This would mean that the stream + % function has been called and streamed some text. + testCase.verifyGreaterThan(numel(sf("")), 1); end function warningJSONResponseFormatGPT35(testCase)