Skip to content

Commit

Permalink
Tool: Tested + Updated load_tool
Browse files Browse the repository at this point in the history
  • Loading branch information
antoninoLorenzo committed Aug 10, 2024
1 parent 6534e0a commit f9d0855
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/agent/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ def __init__(self, name: str, tool_description: str, args_description: str):
def load_tool(path: str):
"""Get tool description from json file"""
with open(path, 'r', encoding='utf-8') as fp:
tool_data = json.load(fp)
tool_data: dict = json.load(fp)
keys = ['name', 'tool_description', 'args_description']

if not isinstance(tool_data, dict):
raise TypeError(f"Wrong format for tool schema at {path}: expected dict but got {type(tool_data)}.")
elif len(tool_data) != 3 or False in [key in keys for key in tool_data.keys()]:
raise ValueError(f"Wrong format for tool schema at {path}: invalid keys.")

name = tool_data['name']
tool_description = ''.join(tool_data['tool_description'])
args_description = ''.join(tool_data['args_description'])

if not (name and tool_description and args_description):
raise ValueError(f"Wrong format for tool schema at {path}: empty values.")

return Tool(name, tool_description, args_description)

@staticmethod
Expand Down

0 comments on commit f9d0855

Please sign in to comment.