pub fn get_tools_limited(
tool_func: impl Fn(Vec<String>, Option<Vec<String>>) -> (Value, usize),
allowed_func_names: Vec<String>,
required_func_names: Option<Vec<String>>,
) -> Result<(Vec<ChatCompletionTool>, usize), OpenAIError>
Expand description
This function will get called if an “allowed_functions” argument is passed to the
run function. If it is passed, then the presense or absence of the function_filtering
feature flag will dictate what happens. If function_filtering is on, then the required
functions (if some) will get included, then your ranked functions will get added until the
token limit is reached. Without function_filtering feature enabled, all functions listed in
allowed_func_names and required_func_names will get sent.
Performs selective inclusion of tools based on the provided allowed_func_names
and the state
of the function_filtering
feature flag. When function_filtering
is enabled and required_func_names
is specified, required functions are prioritized, followed by ranked functions until a token limit is reached.
Without the function_filtering
feature, all functions in allowed_func_names
and required_func_names
are included, irrespective of the token limit.
§Arguments
tool_func
: A function that takes allowed and required function names, and returns tool JSON and total token count.allowed_func_names
: A list of function names allowed for inclusion.required_func_names
: An optional list of function names required for inclusion.
§Returns
A result containing a vector of ChatCompletionTool
objects and the total token count, or an OpenAIError
on failure.
§Errors
Returns an OpenAIError::InvalidArgument
if there’s an issue parsing the tool JSON.