Categories &

Functions List

Class Definition: toolFunction

llms: toolFunction

A toolFunction object for tool-calling capable models.

toolFunction is a scalar class object, which contains the full description of a tool function along with the handle to its corresponding Octave function, which should be executed after a tool call request from the model.

Source Code: toolFunction

Methods

toolFunction: tool = toolFunction (name, description, handle)

tool = toolFunction (name, description, handle) creates a toolFunction object, which comprises an identifier specified by name, a functionality description that can be understood by the LLM model specified in description and a function handle, specified in handle, which corresponds to an actual Octave function that will be evaluated along with any input parameters specified by the LLM’s tool calling response.

By default, toolFunction does not add any input parameters to the created object. Use the addParameters method to append any input input parameters that your function handle may require for its successful evaluation. Use the evalFunction to evaluate the underlying function handle according to the input arguments specified by the LLM.

toolFunction: tool = addParameters (tool, propName, propType, propDescription)
toolFunction: tool = addParameters (tool, propName, propType, propDescription, enum)

addParameters appends the parameters of a single input argument into the toolFunction object so that the LLM can understand the context of the corresponding input argument of the underlying function handle when asking for its evaluation.

addParameters requires at least four input arguments (and may accept an optional fifth argument), which are as described below:

  1. tool (required) A toolFunction object that the parameters will be appended to.
  2. propName (required) A character vector specifying the name of the input argument in the undelying function handle to be evaluated.
  3. propType (required) A character vector specifying the data type of the value corresponding to the input argument specified above.
  4. propDescription (required) A character vector describing the input argument so that the LLM can understand what value to assign for evaluation.
  5. enum (optional) A cell array of character vectors specifying a list of acceptable values that the LLM may chooce from to supply as an input argument. Alternatively, enum can be a cell array of numeric or logical values.
toolFunction: tool_output = evalFunction (tool, tool_call)

tool_output = evalFunction (tool, tool_call) evaluates the function handle of the toolFunction object specified by tool according to the input arguments described by the LLM’s tool calling response specified in tool_call, which can be a character vector containing the appropriate JSON string message or its equivalent to a scalar structure. The returned tool_output is a 1×2 cell array of character vectors, in which the first element contains the output of the evaluated toolFunction object and the second element contains its corresponding function name.