-
Notifications
You must be signed in to change notification settings - Fork 757
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
Validate groups when collect tool packages #3085
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
from promptflow._utils.context_utils import _change_working_dir | ||
from promptflow._utils.utils import is_json_serializable | ||
from promptflow.core._model_configuration import MODEL_CONFIG_NAME_2_CLASS | ||
from promptflow.exceptions import ErrorTarget, UserErrorException | ||
from promptflow.exceptions import ErrorTarget, UserErrorException, ValidationException | ||
|
||
from ..contracts.tool import ( | ||
ConnectionType, | ||
|
@@ -470,6 +470,53 @@ def _get_function_path(function): | |
return func, func_path | ||
|
||
|
||
def validate_groups_if_exist_in_tool_spec(tool): | ||
"""Validate groups if exist in tool spec.""" | ||
tool_name = tool.get("name", "") | ||
groups = tool.get("groups", "") | ||
invalid_group_names = ["advanced"] | ||
used_group_names = set() | ||
used_inputs = set() | ||
for group in groups: | ||
group_name = group.get("name", "") | ||
group_inputs = set(group.get("inputs", [])) | ||
# Group must have name and inputs | ||
if not group_name or not group_inputs: | ||
message_format = "Group must have name and inputs, please check the tool '{0}' and rename the group." | ||
raise ValidationException( | ||
message=message_format.format(tool_name), | ||
message_format=message_format, | ||
ErrorTarget=ErrorTarget.TOOL) | ||
|
||
# Some group names cannot be used like advanced | ||
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. Please explain why. |
||
if group_name.lower() in invalid_group_names: | ||
message_format = "The group name '{0}' cannot be used, please check the tool '{1}' and rename the group." | ||
raise ValidationException( | ||
message=message_format.format(group_name, tool_name), | ||
message_format=message_format, | ||
ErrorTarget=ErrorTarget.TOOL) | ||
|
||
# Group name should be unique | ||
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. I think duplicate group name may hit yaml load error? Why do we not need such logic for tool input name duplication? |
||
if group_name in used_group_names: | ||
message_format = "Group name should be unique, please check the tool '{0}' and rename the group." | ||
raise ValidationException( | ||
message=message_format.format(tool_name), | ||
message_format=message_format, | ||
ErrorTarget=ErrorTarget.TOOL) | ||
else: | ||
used_group_names.add(group_name) | ||
|
||
# Each input shouldn't appear in multiple groups | ||
if len(group_inputs.intersection(used_inputs)) > 0: | ||
message_format = "Each input shouldn't appear in multiple groups, please check the tool '{0}'." | ||
raise ValidationException( | ||
message=message_format.format(tool_name), | ||
message_format=message_format, | ||
ErrorTarget=ErrorTarget.TOOL) | ||
else: | ||
used_inputs.update(group_inputs) | ||
|
||
|
||
class RetrieveToolFuncResultError(UserErrorException): | ||
"""Base exception raised for retrieve tool func result errors.""" | ||
|
||
|
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
invalid -> reserved