Skip to content

Instantly share code, notes, and snippets.

@ocueye2
Created December 11, 2025 20:29
Show Gist options
  • Select an option

  • Save ocueye2/5c60fae3b653655c6d0066e48bfc3b31 to your computer and use it in GitHub Desktop.

Select an option

Save ocueye2/5c60fae3b653655c6d0066e48bfc3b31 to your computer and use it in GitHub Desktop.
toolcall helper
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