Skip to content

Commit

Permalink
Update topenAIChat.m
Browse files Browse the repository at this point in the history
Changing createOpenAIChatWithStreamFunc as suggested by Christopher
  • Loading branch information
vpapanasta committed Apr 26, 2024
1 parent 857fd45 commit 78279d2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/topenAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 78279d2

Please sign in to comment.