Skip to content

Instantly share code, notes, and snippets.

@Madhusuthanan-B
Created July 2, 2024 09:16
Show Gist options
  • Save Madhusuthanan-B/4a0182669ef67441b7a151fa50fc518b to your computer and use it in GitHub Desktop.
Save Madhusuthanan-B/4a0182669ef67441b7a151fa50fc518b to your computer and use it in GitHub Desktop.
export function createToolRunner() {
let availableTools = {};
return {
registerTool: function(name, func) {
availableTools[name] = func;
console.log('registered tools', availableTools);
},
runToolWithInput: function (toolObject) {
const { tool, tool_input } = toolObject;
const toolFunction = availableTools[tool];
if (toolFunction) {
// Check if any key in tool_input should be passed as an object
const args = Object.keys(tool_input).map((key) => {
return tool_input[key];
});
toolFunction(...args);
} else {
console.error("Tool not found:", tool);
}
},
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment