Created
December 11, 2025 20:29
-
-
Save ocueye2/5c60fae3b653655c6d0066e48bfc3b31 to your computer and use it in GitHub Desktop.
toolcall helper
This file contains hidden or 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
| class tools: | |
| def __init__(self,tool_list): | |
| "create a toolset that you can use" | |
| self.tool_list = tool_list | |
| self.tools = list(tool_list.values()) | |
| def evaluate(self,chat,history,fail=False): | |
| "evaluate toolcall from llm" | |
| is_toolcalls = False | |
| if chat.message.tool_calls: | |
| for toolcall in chat.message.tool_calls: | |
| if toolcall.function.name in self.tool_list: | |
| is_toolcalls = True | |
| try: | |
| output = self.tool_list[toolcall.function.name](**toolcall.function.arguments) | |
| history.append({'role': 'tool', 'content': output, 'tool_name': toolcall.function.name}) | |
| except: | |
| if fail: | |
| raise Exception(f"{toolcall} failed with {toolcall.function.arguments}") | |
| else: | |
| history.append({'role': 'tool', 'content': "invalid toolcall", 'tool_name': toolcall.function.name}) | |
| return history, is_toolcalls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment