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

Avoid bogus access to json.choices.delta.content #71

Merged
merged 1 commit into from
Aug 5, 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
3 changes: 2 additions & 1 deletion +llms/+stream/responseStreamer.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
end
this.StreamFun('');
this.ResponseText = txt;
else
elseif isfield(json.choices,"delta") && ...
isfield(json.choices.delta,"content")
txt = json.choices.delta.content;
this.StreamFun(txt);
this.ResponseText = [this.ResponseText txt];
Expand Down
8 changes: 8 additions & 0 deletions tests/topenAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ function invalidInputsConstructor(testCase, InvalidConstructorInput)
testCase.verifyError(@()openAIChat(InvalidConstructorInput.Input{:}), InvalidConstructorInput.Error);
end

function generateWithStreamFunAndMaxNumTokens(testCase)
sf = @(x) fprintf("%s",x);
chat = openAIChat(StreamFun=sf);
result = generate(chat,"Why is a raven like a writing desk?",MaxNumTokens=5);
testCase.verifyClass(result,"string");
testCase.verifyLessThan(strlength(result), 100);
end

function generateWithToolsAndStreamFunc(testCase)
import matlab.unittest.constraints.HasField

Expand Down