Skip to content

Commit c5e2ef1

Browse files
committed
ToolChoice="none" for azureChat
`azureChat` should support `ToolChoice="none"`
1 parent 8d4ca80 commit c5e2ef1

File tree

4 files changed

+27
-54
lines changed

4 files changed

+27
-54
lines changed

Diff for: +llms/+internal/hasTools.m

+27
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,31 @@
1212
Tools
1313
FunctionsStruct
1414
end
15+
16+
methods(Hidden)
17+
function mustBeValidFunctionCall(this, functionCall)
18+
if ~isempty(functionCall)
19+
mustBeTextScalar(functionCall);
20+
if isempty(this.FunctionNames)
21+
error("llms:mustSetFunctionsForCall", llms.utils.errorMessageCatalog.getMessage("llms:mustSetFunctionsForCall"));
22+
end
23+
mustBeMember(functionCall, ["none","auto", this.FunctionNames]);
24+
end
25+
end
26+
27+
function toolChoice = convertToolChoice(this, toolChoice)
28+
% if toolChoice is empty
29+
if isempty(toolChoice)
30+
% if Tools is not empty, the default is 'auto'.
31+
if ~isempty(this.Tools)
32+
toolChoice = "auto";
33+
end
34+
elseif ~ismember(toolChoice,["auto","none"])
35+
% if toolChoice is not empty, then it must be "auto", "none" or in the format
36+
% {"type": "function", "function": {"name": "my_function"}}
37+
toolChoice = struct("type","function","function",struct("name",toolChoice));
38+
end
39+
40+
end
41+
end
1542
end

Diff for: azureChat.m

-25
Original file line numberDiff line numberDiff line change
@@ -289,31 +289,6 @@
289289
end
290290

291291
methods(Hidden)
292-
function mustBeValidFunctionCall(this, functionCall)
293-
if ~isempty(functionCall)
294-
mustBeTextScalar(functionCall);
295-
if isempty(this.FunctionNames)
296-
error("llms:mustSetFunctionsForCall", llms.utils.errorMessageCatalog.getMessage("llms:mustSetFunctionsForCall"));
297-
end
298-
mustBeMember(functionCall, ["none","auto", this.FunctionNames]);
299-
end
300-
end
301-
302-
function toolChoice = convertToolChoice(this, toolChoice)
303-
% if toolChoice is empty
304-
if isempty(toolChoice)
305-
% if Tools is not empty, the default is 'auto'.
306-
if ~isempty(this.Tools)
307-
toolChoice = "auto";
308-
end
309-
elseif toolChoice ~= "auto"
310-
% if toolChoice is not empty, then it must be in the format
311-
% {"type": "function", "function": {"name": "my_function"}}
312-
toolChoice = struct("type","function","function",struct("name",toolChoice));
313-
end
314-
315-
end
316-
317292
function messageStruct = encodeImages(~, messageStruct)
318293
for k=1:numel(messageStruct)
319294
if isfield(messageStruct{k},"images")

Diff for: openAIChat.m

-25
Original file line numberDiff line numberDiff line change
@@ -270,31 +270,6 @@
270270
end
271271

272272
methods(Hidden)
273-
function mustBeValidFunctionCall(this, functionCall)
274-
if ~isempty(functionCall)
275-
mustBeTextScalar(functionCall);
276-
if isempty(this.FunctionNames)
277-
error("llms:mustSetFunctionsForCall", llms.utils.errorMessageCatalog.getMessage("llms:mustSetFunctionsForCall"));
278-
end
279-
mustBeMember(functionCall, ["none","auto", this.FunctionNames]);
280-
end
281-
end
282-
283-
function toolChoice = convertToolChoice(this, toolChoice)
284-
% if toolChoice is empty
285-
if isempty(toolChoice)
286-
% if Tools is not empty, the default is 'auto'.
287-
if ~isempty(this.Tools)
288-
toolChoice = "auto";
289-
end
290-
elseif ~ismember(toolChoice,["auto","none"])
291-
% if toolChoice is not empty, then it must be "auto", "none" or in the format
292-
% {"type": "function", "function": {"name": "my_function"}}
293-
toolChoice = struct("type","function","function",struct("name",toolChoice));
294-
end
295-
296-
end
297-
298273
function messageStruct = encodeImages(~, messageStruct)
299274
for k=1:numel(messageStruct)
300275
if isfield(messageStruct{k},"images")

Diff for: tests/tazureChat.m

-4
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ function deploymentNotFound(testCase)
172172
end
173173

174174
% open TODOs for azureChat
175-
function settingToolChoiceWithNone(testCase)
176-
testCase.assumeFail("azureChat need different handling of ToolChoice 'none'");
177-
end
178-
179175
function generateWithToolsAndStreamFunc(testCase)
180176
testCase.assumeFail("need to make azureChat return tool_call in the same way as openAIChat");
181177
end

0 commit comments

Comments
 (0)