Skip to content

Commit

Permalink
ToolChoice="none" for azureChat
Browse files Browse the repository at this point in the history
`azureChat` should support `ToolChoice="none"`
  • Loading branch information
ccreutzi committed Nov 5, 2024
1 parent 8d4ca80 commit c5e2ef1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 54 deletions.
27 changes: 27 additions & 0 deletions +llms/+internal/hasTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,31 @@
Tools
FunctionsStruct
end

methods(Hidden)
function mustBeValidFunctionCall(this, functionCall)
if ~isempty(functionCall)
mustBeTextScalar(functionCall);
if isempty(this.FunctionNames)
error("llms:mustSetFunctionsForCall", llms.utils.errorMessageCatalog.getMessage("llms:mustSetFunctionsForCall"));
end
mustBeMember(functionCall, ["none","auto", this.FunctionNames]);
end
end

function toolChoice = convertToolChoice(this, toolChoice)
% if toolChoice is empty
if isempty(toolChoice)
% if Tools is not empty, the default is 'auto'.
if ~isempty(this.Tools)
toolChoice = "auto";
end
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

end
end
end
25 changes: 0 additions & 25 deletions azureChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,31 +289,6 @@
end

methods(Hidden)
function mustBeValidFunctionCall(this, functionCall)
if ~isempty(functionCall)
mustBeTextScalar(functionCall);
if isempty(this.FunctionNames)
error("llms:mustSetFunctionsForCall", llms.utils.errorMessageCatalog.getMessage("llms:mustSetFunctionsForCall"));
end
mustBeMember(functionCall, ["none","auto", this.FunctionNames]);
end
end

function toolChoice = convertToolChoice(this, toolChoice)
% if toolChoice is empty
if isempty(toolChoice)
% if Tools is not empty, the default is 'auto'.
if ~isempty(this.Tools)
toolChoice = "auto";
end
elseif toolChoice ~= "auto"
% if toolChoice is not empty, then it must be in the format
% {"type": "function", "function": {"name": "my_function"}}
toolChoice = struct("type","function","function",struct("name",toolChoice));
end

end

function messageStruct = encodeImages(~, messageStruct)
for k=1:numel(messageStruct)
if isfield(messageStruct{k},"images")
Expand Down
25 changes: 0 additions & 25 deletions openAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -270,31 +270,6 @@
end

methods(Hidden)
function mustBeValidFunctionCall(this, functionCall)
if ~isempty(functionCall)
mustBeTextScalar(functionCall);
if isempty(this.FunctionNames)
error("llms:mustSetFunctionsForCall", llms.utils.errorMessageCatalog.getMessage("llms:mustSetFunctionsForCall"));
end
mustBeMember(functionCall, ["none","auto", this.FunctionNames]);
end
end

function toolChoice = convertToolChoice(this, toolChoice)
% if toolChoice is empty
if isempty(toolChoice)
% if Tools is not empty, the default is 'auto'.
if ~isempty(this.Tools)
toolChoice = "auto";
end
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

end

function messageStruct = encodeImages(~, messageStruct)
for k=1:numel(messageStruct)
if isfield(messageStruct{k},"images")
Expand Down
4 changes: 0 additions & 4 deletions tests/tazureChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ function deploymentNotFound(testCase)
end

% open TODOs for azureChat
function settingToolChoiceWithNone(testCase)
testCase.assumeFail("azureChat need different handling of ToolChoice 'none'");
end

function generateWithToolsAndStreamFunc(testCase)
testCase.assumeFail("need to make azureChat return tool_call in the same way as openAIChat");
end
Expand Down

0 comments on commit c5e2ef1

Please sign in to comment.