Created
July 2, 2024 09:16
-
-
Save Madhusuthanan-B/4a0182669ef67441b7a151fa50fc518b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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