-
Notifications
You must be signed in to change notification settings - Fork 725
MAINT: Remove unused fields in MessagePiece #1616
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
Draft
behnam-o
wants to merge
14
commits into
microsoft:main
Choose a base branch
from
behnam-o:dev/message-piece-unused
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
303cafc
Remove unused fields in message_piece
940e0e2
revert unwanted changes
98d054c
immutable prop
df19b36
ref public prop
8d8cc16
deprecate instead of remove
c333ba3
update md
06e9d71
Merge branch 'main' into dev/message-piece-unused
8e58b47
import warning
9508f75
tests for CC
b64c9ab
test fix
0d7958f
revert notebooks
4940436
revert notebook
cc76142
no deprecate, just remove
a203006
fix _scores definition
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
|
|
||
| import uuid | ||
| from datetime import datetime, timezone | ||
| from typing import TYPE_CHECKING, Any, Literal, Optional, Union, get_args | ||
| from typing import TYPE_CHECKING, Any, Optional, Union, get_args | ||
| from uuid import uuid4 | ||
|
|
||
| from pyrit.identifiers.component_identifier import ComponentIdentifier | ||
|
|
@@ -14,8 +14,6 @@ | |
| if TYPE_CHECKING: | ||
| from pyrit.models.score import Score | ||
|
|
||
| Originator = Literal["attack", "converter", "undefined", "scorer"] | ||
|
|
||
|
|
||
| class MessagePiece: | ||
| """ | ||
|
|
@@ -42,15 +40,11 @@ def __init__( | |
| converter_identifiers: Optional[list[Union[ComponentIdentifier, dict[str, str]]]] = None, | ||
| prompt_target_identifier: Optional[Union[ComponentIdentifier, dict[str, Any]]] = None, | ||
| attack_identifier: Optional[Union[ComponentIdentifier, dict[str, str]]] = None, | ||
| scorer_identifier: Optional[Union[ComponentIdentifier, dict[str, str]]] = None, | ||
|
Contributor
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. why do we get rid of scorer_identifier but not the other identifiers ? |
||
| original_value_data_type: PromptDataType = "text", | ||
| converted_value_data_type: Optional[PromptDataType] = None, | ||
| response_error: PromptResponseError = "none", | ||
| originator: Originator = "undefined", | ||
| original_prompt_id: Optional[uuid.UUID] = None, | ||
| timestamp: Optional[datetime] = None, | ||
| scores: Optional[list[Score]] = None, | ||
| targeted_harm_categories: Optional[list[str]] = None, | ||
| ): | ||
| """ | ||
| Initialize a MessagePiece. | ||
|
|
@@ -74,16 +68,11 @@ def __init__( | |
| objects or dicts (deprecated, will be removed in 0.14.0). Defaults to None. | ||
| prompt_target_identifier: The target identifier for the prompt. Defaults to None. | ||
| attack_identifier: The attack identifier for the prompt. Defaults to None. | ||
| scorer_identifier: The scorer identifier for the prompt. Accepts a ComponentIdentifier. | ||
| Defaults to None. | ||
| original_value_data_type: The data type of the original prompt (text, image). Defaults to "text". | ||
| converted_value_data_type: The data type of the converted prompt (text, image). Defaults to "text". | ||
| response_error: The response error type. Defaults to "none". | ||
| originator: The originator of the prompt. Defaults to "undefined". | ||
| original_prompt_id: The original prompt id. It is equal to id unless it is a duplicate. Defaults to None. | ||
| timestamp: The timestamp of the memory entry. Defaults to None (auto-generated). | ||
| scores: The scores associated with the prompt. Defaults to None. | ||
| targeted_harm_categories: The harm categories associated with the prompt. Defaults to None. | ||
|
|
||
| Raises: | ||
| ValueError: If role, data types, or response error are invalid. | ||
|
|
@@ -134,11 +123,6 @@ def __init__( | |
| ComponentIdentifier.normalize(attack_identifier) if attack_identifier else None | ||
| ) | ||
|
|
||
| # Handle scorer_identifier: normalize to ComponentIdentifier (handles dict with deprecation warning) | ||
| self.scorer_identifier: Optional[ComponentIdentifier] = ( | ||
| ComponentIdentifier.normalize(scorer_identifier) if scorer_identifier else None | ||
| ) | ||
|
|
||
| self.original_value = original_value | ||
|
|
||
| if original_value_data_type not in get_args(PromptDataType): | ||
|
|
@@ -161,13 +145,21 @@ def __init__( | |
| raise ValueError(f"response_error {response_error} is not a valid response error.") | ||
|
|
||
| self.response_error = response_error | ||
| self.originator = originator | ||
|
|
||
| # Original prompt id defaults to id (assumes that this is the original prompt, not a duplicate) | ||
| self.original_prompt_id = original_prompt_id or self.id | ||
|
|
||
| self.scores = scores if scores else [] | ||
| self.targeted_harm_categories = targeted_harm_categories if targeted_harm_categories else [] | ||
| # Scores are not set via constructor. They are hydrated by the memory layer | ||
| # via _set_scores() after construction. | ||
| self._scores: list[Score] = [] | ||
|
|
||
| @property | ||
| def scores(self) -> list[Score]: | ||
| """Scores associated with this message piece, hydrated by the memory layer.""" | ||
| return list(self._scores) | ||
|
|
||
| def _set_scores(self, scores: list[Score]) -> None: | ||
| self._scores = scores | ||
|
behnam-o marked this conversation as resolved.
|
||
|
|
||
| async def set_sha256_values_async(self) -> None: | ||
| """ | ||
|
|
@@ -280,22 +272,19 @@ def to_dict(self) -> dict[str, object]: | |
| "sequence": self.sequence, | ||
| "timestamp": self.timestamp.isoformat() if self.timestamp else None, | ||
| "labels": self.labels, | ||
| "targeted_harm_categories": self.targeted_harm_categories if self.targeted_harm_categories else None, | ||
| "prompt_metadata": self.prompt_metadata, | ||
| "converter_identifiers": [conv.to_dict() for conv in self.converter_identifiers], | ||
| "prompt_target_identifier": ( | ||
| self.prompt_target_identifier.to_dict() if self.prompt_target_identifier else None | ||
| ), | ||
| "attack_identifier": self.attack_identifier.to_dict() if self.attack_identifier else None, | ||
| "scorer_identifier": self.scorer_identifier.to_dict() if self.scorer_identifier else None, | ||
| "original_value_data_type": self.original_value_data_type, | ||
| "original_value": self.original_value, | ||
| "original_value_sha256": self.original_value_sha256, | ||
| "converted_value_data_type": self.converted_value_data_type, | ||
| "converted_value": self.converted_value, | ||
| "converted_value_sha256": self.converted_value_sha256, | ||
| "response_error": self.response_error, | ||
| "originator": self.originator, | ||
| "original_prompt_id": str(self.original_prompt_id), | ||
| "scores": [score.to_dict() for score in self.scores], | ||
| } | ||
|
|
||
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.