Skip to content

Commit

Permalink
Merge pull request #12 from matlab-deep-learning/dev-fix-ToolChoice-bug
Browse files Browse the repository at this point in the history
Dev fix tool choice bug
  • Loading branch information
debymf committed Mar 3, 2024
2 parents efa591b + 544d271 commit c00241a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions openAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ function mustBeValidFunctionCall(this, functionCall)
if ~isempty(this.Tools)
toolChoice = "auto";
end
elseif ToolChoice ~= "auto"
% if toolChoice is not empty, then it must be in the format
elseif ~ismember(toolChoice,["auto","none"])
% if toolChoice is not empty, then it must be "auto", "none" or in the format
% {"type": "function", "function": {"name": "my_function"}}
toolChoice = struct("type","function","function",struct("name",toolChoice));
end
Expand Down
6 changes: 6 additions & 0 deletions tests/topenAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ function errorsWhenPassingToolChoiceWithEmptyTools(testCase)
testCase.verifyError(@()generate(chat,"input", ToolChoice="bla"), "llms:mustSetFunctionsForCall");
end

function settingToolChoiceWithNone(testCase)
functions = openAIFunction("funName");
chat = openAIChat(ApiKey="this-is-not-a-real-key",Tools=functions);
testCase.verifyWarningFree(@()generate(chat,"This is okay","ToolChoice","none"));
end

function invalidInputsConstructor(testCase, InvalidConstructorInput)
testCase.verifyError(@()openAIChat(InvalidConstructorInput.Input{:}), InvalidConstructorInput.Error);
end
Expand Down

0 comments on commit c00241a

Please sign in to comment.