-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathavailable_tools.py
More file actions
64 lines (58 loc) · 2.4 KB
/
available_tools.py
File metadata and controls
64 lines (58 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import logging
class VersionException(Exception):
pass
class FileIDException(Exception):
pass
class FileTypeException(Exception):
pass
def add_yaml_to_dict(table, key, yaml):
"""Add the yaml to the table, but raise an error if the id isn't unique """
if key in table:
raise FileIDException(str(key))
table.update({key: yaml})
class AvailableTools:
"""
This class is used for storing dictionaries of all the available
personalities, taskflows, and prompts.
"""
def __init__(self, yamls: dict):
self.personalities = {}
self.taskflows = {}
self.prompts = {}
self.toolboxes = {}
self.model_config = {}
# Iterate through all the yaml files and divide them into categories.
# Each file should contain a header like this:
#
# seclab-taskflow-agent:
# type: taskflow
# version: 1
#
for path, yaml in yamls.items():
try:
header = yaml['seclab-taskflow-agent']
version = header['version']
if version != 1:
raise VersionException(str(version))
filekey = header['filekey']
filetype = header['filetype']
if filetype == 'personality':
add_yaml_to_dict(self.personalities, filekey, yaml)
elif filetype == 'taskflow':
add_yaml_to_dict(self.taskflows, filekey, yaml)
elif filetype == 'prompt':
add_yaml_to_dict(self.prompts, filekey, yaml)
elif filetype == 'toolbox':
add_yaml_to_dict(self.toolboxes, filekey, yaml)
elif filetype == 'model_config':
add_yaml_to_dict(self.model_config, filekey, yaml)
else:
raise FileTypeException(str(filetype))
except KeyError as err:
logging.error(f'{path} does not contain the key {err.args[0]}')
except VersionException as err:
logging.error(f'{path}: seclab-taskflow-agent version {err.args[0]} is not supported')
except FileIDException as err:
logging.error(f'{path}: file ID {err.args[0]} is not unique')
except FileTypeException as err:
logging.error(f'{path}: seclab-taskflow-agent file type {err.args[0]} is not supported')