From da8e9811570c9a6e07164dd0dc769a88ef9a504c Mon Sep 17 00:00:00 2001 From: Toshiaki Takeuchi Date: Thu, 29 Feb 2024 17:16:12 -0500 Subject: [PATCH 1/4] Fix ToolChoice bug --- openAIChat.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openAIChat.m b/openAIChat.m index 54db2a0..55c19a5 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 From 5505b32049baa0ec1697703ce567541fabed5611 Mon Sep 17 00:00:00 2001 From: Toshiaki Takeuchi Date: Thu, 29 Feb 2024 17:25:58 -0500 Subject: [PATCH 2/4] Fix Typo toolChoice, not ToolChoice --- openAIChat.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openAIChat.m b/openAIChat.m index 55c19a5..aced1cb 100644 --- a/openAIChat.m +++ b/openAIChat.m @@ -311,7 +311,7 @@ function mustBeValidFunctionCall(this, functionCall) if ~isempty(this.Tools) toolChoice = "auto"; end - elseif ~ismember(ToolChoice,["auto","none"]) + 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)); From 67369378e5ebc82f537b843df4e094dccf1f713d Mon Sep 17 00:00:00 2001 From: Toshiaki Takeuchi Date: Fri, 1 Mar 2024 06:43:44 -0500 Subject: [PATCH 3/4] Add a test case for ToolChoice="none" --- tests/topenAIChat.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/topenAIChat.m b/tests/topenAIChat.m index bdcffe7..92e62db 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 errorsWhenPassingToolChoiceWithNone(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 From 544d27136b8a6533f057a5a4d78e6d15d86e530a Mon Sep 17 00:00:00 2001 From: Toshiaki Takeuchi Date: Fri, 1 Mar 2024 17:16:47 -0500 Subject: [PATCH 4/4] Rename a test case --- tests/topenAIChat.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/topenAIChat.m b/tests/topenAIChat.m index 92e62db..390ec9e 100644 --- a/tests/topenAIChat.m +++ b/tests/topenAIChat.m @@ -77,7 +77,7 @@ function errorsWhenPassingToolChoiceWithEmptyTools(testCase) testCase.verifyError(@()generate(chat,"input", ToolChoice="bla"), "llms:mustSetFunctionsForCall"); end - function errorsWhenPassingToolChoiceWithNone(testCase) + 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"));