diff --git a/openAIChat.m b/openAIChat.m index 54db2a0..aced1cb 100644 --- a/openAIChat.m +++ b/openAIChat.m @@ -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 diff --git a/tests/topenAIChat.m b/tests/topenAIChat.m index bdcffe7..390ec9e 100644 --- a/tests/topenAIChat.m +++ b/tests/topenAIChat.m @@ -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