-
Notifications
You must be signed in to change notification settings - Fork 24
Add support for namespace alias #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,7 @@ def __init__(self, yamls: dict): | |||||||||||||||||||||||||
| self.prompts = {} | ||||||||||||||||||||||||||
| self.toolboxes = {} | ||||||||||||||||||||||||||
| self.model_config = {} | ||||||||||||||||||||||||||
| self.namespace_config = {} | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Iterate through all the yaml files and divide them into categories. | ||||||||||||||||||||||||||
| # Each file should contain a header like this: | ||||||||||||||||||||||||||
|
|
@@ -52,6 +53,8 @@ def __init__(self, yamls: dict): | |||||||||||||||||||||||||
| add_yaml_to_dict(self.toolboxes, filekey, yaml) | ||||||||||||||||||||||||||
| elif filetype == 'model_config': | ||||||||||||||||||||||||||
| add_yaml_to_dict(self.model_config, filekey, yaml) | ||||||||||||||||||||||||||
| elif filetype == 'namespace_config': | ||||||||||||||||||||||||||
| add_yaml_to_dict(self.namespace_config, filekey, yaml) | ||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||
| raise FileTypeException(str(filetype)) | ||||||||||||||||||||||||||
| except KeyError as err: | ||||||||||||||||||||||||||
|
|
@@ -62,3 +65,40 @@ def __init__(self, yamls: dict): | |||||||||||||||||||||||||
| 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') | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def copy_with_alias(self, alias_dict : dict) -> dict: | ||||||||||||||||||||||||||
| def _copy_add_alias_to_dict(original_dict : dict, alias_dict : dict) -> dict: | ||||||||||||||||||||||||||
| new_dict = dict(original_dict) | ||||||||||||||||||||||||||
| alias_keys = alias_dict.keys() | ||||||||||||||||||||||||||
| for k,v in original_dict.items(): | ||||||||||||||||||||||||||
| for ak in alias_keys: | ||||||||||||||||||||||||||
| if k.startswith(ak) and k[len(ak)] == '/': | ||||||||||||||||||||||||||
| new_key = alias_dict[ak] + k[len(ak):] | ||||||||||||||||||||||||||
| new_dict[new_key] = v | ||||||||||||||||||||||||||
|
Comment on lines
+72
to
+77
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop over
Suggested change
|
||||||||||||||||||||||||||
| return new_dict | ||||||||||||||||||||||||||
| new_available_tools = AvailableTools({}) | ||||||||||||||||||||||||||
| new_available_tools.personalities = _copy_add_alias_to_dict(self.personalities, alias_dict) | ||||||||||||||||||||||||||
| new_available_tools.taskflows = _copy_add_alias_to_dict(self.taskflows, alias_dict) | ||||||||||||||||||||||||||
| new_available_tools.prompts = _copy_add_alias_to_dict(self.prompts, alias_dict) | ||||||||||||||||||||||||||
| #toolboxes are looked up after canonicalized | ||||||||||||||||||||||||||
| new_available_tools.toolboxes = dict(self.toolboxes) | ||||||||||||||||||||||||||
| new_available_tools.model_config = _copy_add_alias_to_dict(self.model_config, alias_dict) | ||||||||||||||||||||||||||
| new_available_tools.namespace_config = _copy_add_alias_to_dict(self.namespace_config, alias_dict) | ||||||||||||||||||||||||||
| return new_available_tools | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def canonicalize_toolboxes(toolboxes : list, alias_dict : dict) -> list: | ||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
| Toolboxes needs to be canonicalize because both personalities and taskflows can use toolboxes with potentially different aliases | ||||||||||||||||||||||||||
|
m-y-mo marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
| out = set() | ||||||||||||||||||||||||||
| if not alias_dict: | ||||||||||||||||||||||||||
| return toolboxes | ||||||||||||||||||||||||||
| for tb in toolboxes: | ||||||||||||||||||||||||||
| found_alias = False | ||||||||||||||||||||||||||
| for k,v in alias_dict.items(): | ||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above about looping over all the aliases. |
||||||||||||||||||||||||||
| if tb.startswith(v) and tb[len(v)] == '/': | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| out.add(k + tb[len(v):]) | ||||||||||||||||||||||||||
| found_alias = True | ||||||||||||||||||||||||||
| if not found_alias: | ||||||||||||||||||||||||||
| out.add(tb) | ||||||||||||||||||||||||||
| return list(out) | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| seclab-taskflow-agent: | ||
| version: 1 | ||
| filetype: namespace_config | ||
| filekey: GitHubSecurityLab/seclab-taskflow-agent/configs/namespace_config | ||
| namespace_aliases: | ||
| GitHubSecurityLab/seclab-taskflow-agent : seclab-ta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will raise an IndexError if a key equals the alias exactly. Add a length check:
if k.startswith(ak) and len(k) > len(ak) and k[len(ak)] == '/':