Tool Calling
ExperimentalLarge language models are capable of performing a wide variety of tasks, but they can't do everything. They are typically bad at things such as math and their knowledge might be outdated because its only seen things up to its training cutoff date.
Sometimes you need to call out to a tool or service to augment its capabilities. Mixlayer makes this easy by providing a way to call out to tools from within your code.
How it works
When you call install
with a tool definition, Mixlayer will insert a prompt into the context window to notify the model that the tool is available.
Any subsequent calls to gen
will give the model an opportunity to invoke the tool if it thinks it'll be useful.
Examples
Calculator
In this example, we provide the model with a "calculator" tool. It simply evaluates a mathematical expression using the eval
JS function and returns the result.
const MATH_TOOL = {
name: 'calculator',
description: 'Evaluate mathematical expressions',
fn: ({expression}) => {
return { answer: eval(expression) };
},
parameters: {
expression: {
param_type: 'string',
description: 'Math problem to evaluate',
required: true
}
}
}
install(MATH_TOOL);
prompt(`what is 96 * 124?`, { role: 'user' });
gen({limit: 500, role: 'assistant' });