Skip to content

Commit

Permalink
Merge pull request #71 from matlab-deep-learning/avoid-content-error
Browse files Browse the repository at this point in the history
Avoid bogus access to `json.choices.delta.content`
  • Loading branch information
ccreutzi committed Aug 5, 2024
2 parents 062538c + 53c1df5 commit fce8bb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit fce8bb8

Please sign in to comment.