-
Notifications
You must be signed in to change notification settings - Fork 745
FEAT Migrate consumers to TargetConfiguration capability checks
#1645
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
Open
hannahwestra25
wants to merge
19
commits into
microsoft:main
Choose a base branch
from
hannahwestra25:hawestra/move_to_target_config
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.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f1186d9
remove promptchattarget ref in converters & add native target require…
hannahwestra25 229d3b9
whitespace
hannahwestra25 d9e0784
Merge branch 'main' of https://github.com/microsoft/PyRIT into hawest…
hannahwestra25 bf7fcad
remove required native capabilities and simplify targetrequirements
hannahwestra25 c00285c
move validation func
hannahwestra25 3aec335
Merge branch 'main' of https://github.com/microsoft/PyRIT into hawest…
hannahwestra25 8a43590
remove remaining promptchattarget and unused requirements
hannahwestra25 b1edf25
remove lingering chat target ref
hannahwestra25 1915c82
fix docstrings
hannahwestra25 1a51bb0
Merge branch 'main' of https://github.com/microsoft/PyRIT into hawest…
hannahwestra25 d2cb04b
correct chat definition
hannahwestra25 c354d6c
Merge branch 'main' of https://github.com/microsoft/PyRIT into hawest…
hannahwestra25 32e75d0
centralize validation and fix docstrings
hannahwestra25 e0978fe
Merge branch 'main' of https://github.com/microsoft/PyRIT into hawest…
hannahwestra25 922cb2d
fix tests
hannahwestra25 82fb70a
centralize converter validation and fix crescendo check
hannahwestra25 2afdcd3
add scenario validation
hannahwestra25 386357f
add known capabilities
hannahwestra25 890e11b
create adversarial target for TAP
hannahwestra25 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,9 @@ | |
| SeedPrompt, | ||
| ) | ||
| from pyrit.prompt_normalizer import PromptNormalizer | ||
| from pyrit.prompt_target import PromptChatTarget | ||
| from pyrit.prompt_target import PromptTarget | ||
| from pyrit.prompt_target.common.target_capabilities import CapabilityName | ||
| from pyrit.prompt_target.common.target_requirements import TargetRequirements | ||
| from pyrit.score import ( | ||
| FloatScaleThresholdScorer, | ||
| Scorer, | ||
|
|
@@ -112,6 +114,16 @@ class CrescendoAttack(MultiTurnAttackStrategy[CrescendoAttackContext, CrescendoA | |
| You can learn more about the Crescendo attack [@russinovich2024crescendo]. | ||
| """ | ||
|
|
||
| # Crescendo fundamentally relies on multi-turn conversation history to | ||
| # gradually escalate prompts; history-squash adaptation would collapse the | ||
| # conversation into a single prompt and silently break the attack's | ||
| # semantics. Declare MULTI_TURN as native_required so adaptation is | ||
| # rejected at construction time. | ||
| TARGET_REQUIREMENTS = TargetRequirements( | ||
| required=frozenset({CapabilityName.EDITABLE_HISTORY, CapabilityName.MULTI_TURN}), | ||
|
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. "Editable" is a bit misleading. In truth, it means "branchable". We only append to history, and don't edit it. |
||
| native_required=frozenset({CapabilityName.MULTI_TURN}), | ||
| ) | ||
|
|
||
| # Default system prompt template path for Crescendo attack | ||
| DEFAULT_ADVERSARIAL_CHAT_SYSTEM_PROMPT_TEMPLATE_PATH: Path = ( | ||
| Path(EXECUTOR_SEED_PROMPT_PATH) / "crescendo" / "crescendo_variant_1.yaml" | ||
|
|
@@ -121,7 +133,7 @@ class CrescendoAttack(MultiTurnAttackStrategy[CrescendoAttackContext, CrescendoA | |
| def __init__( | ||
| self, | ||
| *, | ||
| objective_target: PromptChatTarget = REQUIRED_VALUE, # type: ignore[assignment] | ||
| objective_target: PromptTarget = REQUIRED_VALUE, # type: ignore[assignment] | ||
| attack_adversarial_config: AttackAdversarialConfig, | ||
| attack_converter_config: Optional[AttackConverterConfig] = None, | ||
| attack_scoring_config: Optional[AttackScoringConfig] = None, | ||
|
|
@@ -134,7 +146,8 @@ def __init__( | |
| Initialize the Crescendo attack strategy. | ||
|
|
||
| Args: | ||
| objective_target (PromptChatTarget): The target system to attack. Must be a PromptChatTarget. | ||
| objective_target (PromptTarget): The target system to attack. Must | ||
| support editable conversation history. | ||
| attack_adversarial_config (AttackAdversarialConfig): Configuration for the adversarial component, | ||
| including the adversarial chat target and optional system prompt path. | ||
| attack_converter_config (Optional[AttackConverterConfig]): Configuration for attack converters, | ||
|
|
@@ -148,7 +161,7 @@ def __init__( | |
| application by role, message normalization, and non-chat target behavior. | ||
|
|
||
| Raises: | ||
| ValueError: If objective_target is not a PromptChatTarget. | ||
| ValueError: If objective_target does not natively support editable history. | ||
| """ | ||
| # Initialize base class | ||
| super().__init__(objective_target=objective_target, logger=logger, context_type=CrescendoAttackContext) | ||
|
|
@@ -257,17 +270,7 @@ async def _setup_async(self, *, context: CrescendoAttackContext) -> None: | |
|
|
||
| Args: | ||
| context (CrescendoAttackContext): Attack context with configuration | ||
|
|
||
| Raises: | ||
| ValueError: If the objective target does not support multi-turn conversations. | ||
| """ | ||
| if not self._objective_target.capabilities.supports_multi_turn: | ||
| raise ValueError( | ||
| "CrescendoAttack requires a multi-turn target. Crescendo fundamentally relies on " | ||
| "multi-turn conversation history to gradually escalate prompts. " | ||
| "Use RedTeamingAttack or TreeOfAttacksWithPruning instead." | ||
| ) | ||
|
|
||
| # Ensure the context has a session | ||
| context.session = ConversationSession() | ||
|
|
||
|
|
||
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
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.