matlab-deep-learning / llms-with-matlab

Connect MATLAB to LLM APIs, including OpenAI® Chat Completions, Azure® OpenAI Services, and Ollama™
Other
97 stars 21 forks source link

ToolChoice not accepting "none" #11

Closed toshiakit closed 6 months ago

toshiakit commented 6 months ago

Currently you cannot select "none" for ToolChoice

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

We should fix this

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 "none" or in the format
        % {"type": "function", "function": {"name": "my_function"}}
        toolChoice = struct("type","function","function",struct("name",toolChoice));
    end

end