Skip to content

Commit d0c8833

Browse files
romanlutzCopilot
andauthored
MAINT Remove v0.14.0 deprecations (#1748)
Co-authored-by: romanlutz <romanlutz@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3cfa661 commit d0c8833

27 files changed

Lines changed: 14 additions & 307 deletions

pyrit/cli/pyrit_shell.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
from pyrit.cli import _banner as banner
2828
from pyrit.cli._cli_args import merge_config_scenario_args
29-
from pyrit.common.deprecation import print_deprecation_message
3029
from pyrit.registry import ScenarioRegistry
3130

3231

@@ -73,7 +72,6 @@ def __init__(
7372
initializer_names: Optional[list[Any]] = None,
7473
env_files: Optional[list[Path]] = None,
7574
log_level: Optional[int] = None,
76-
context: Optional[frontend_core.FrontendCore] = None,
7775
) -> None:
7876
"""
7977
Initialize the PyRIT shell.
@@ -90,12 +88,6 @@ def __init__(
9088
initializer_names (Optional[list[Any]]): Initializer entries (names or dicts).
9189
env_files (Optional[list[Path]]): Environment file paths to load in order.
9290
log_level (Optional[int]): Logging level constant (e.g., ``logging.WARNING``).
93-
context (Optional[frontend_core.FrontendCore]): Deprecated. Pre-created FrontendCore
94-
context. Use the individual keyword arguments instead.
95-
96-
Raises:
97-
ValueError: If ``context`` is provided together with any other
98-
FrontendCore keyword arguments.
9991
"""
10092
super().__init__()
10193
self._no_animation = no_animation
@@ -112,21 +104,6 @@ def __init__(
112104
if v is not None
113105
}
114106

115-
if context is not None:
116-
if self._context_kwargs:
117-
raise ValueError(
118-
"Cannot pass 'context' together with FrontendCore keyword arguments "
119-
f"({', '.join(self._context_kwargs)}). Use one or the other."
120-
)
121-
print_deprecation_message(
122-
old_item="PyRITShell(context=...)",
123-
new_item="PyRITShell(database=..., log_level=..., ...)",
124-
removed_in="0.14.0",
125-
)
126-
self._deprecated_context: frontend_core.FrontendCore | None = context
127-
else:
128-
self._deprecated_context = None
129-
130107
# Track scenario execution history: list of (command_string, ScenarioResult) tuples
131108
self._scenario_history: list[tuple[str, ScenarioResult]] = []
132109

@@ -147,10 +124,7 @@ def _background_init(self) -> None:
147124
from pyrit.cli import frontend_core as fc
148125

149126
self._fc = fc
150-
if self._deprecated_context is not None:
151-
self.context = self._deprecated_context
152-
else:
153-
self.context = fc.FrontendCore(**self._context_kwargs)
127+
self.context = fc.FrontendCore(**self._context_kwargs)
154128
self.default_log_level = self.context._log_level
155129
asyncio.run(self.context.initialize_async())
156130
except BaseException as exc:

pyrit/executor/attack/single_turn/many_shot_jailbreak.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Any, Optional
77

88
from pyrit.common.apply_defaults import REQUIRED_VALUE, apply_defaults
9-
from pyrit.common.deprecation import print_deprecation_message
109
from pyrit.common.path import DATASETS_PATH, JAILBREAK_TEMPLATES_PATH
1110
from pyrit.executor.attack.core.attack_config import AttackConverterConfig, AttackScoringConfig
1211
from pyrit.executor.attack.core.attack_parameters import AttackParameters
@@ -37,21 +36,6 @@ def load_many_shot_jailbreaking_dataset() -> list[dict[str, str]]:
3736
return data
3837

3938

40-
def fetch_many_shot_jailbreaking_dataset() -> list[dict[str, str]]:
41-
"""
42-
Load many-shot jailbreaking examples (deprecated, use load_many_shot_jailbreaking_dataset).
43-
44-
Returns:
45-
list[dict[str, str]]: A list of many-shot jailbreaking examples.
46-
"""
47-
print_deprecation_message(
48-
old_item=fetch_many_shot_jailbreaking_dataset,
49-
new_item=load_many_shot_jailbreaking_dataset,
50-
removed_in="0.14.0",
51-
)
52-
return load_many_shot_jailbreaking_dataset()
53-
54-
5539
class ManyShotJailbreakAttack(PromptSendingAttack):
5640
"""
5741
Implement the Many Shot Jailbreak method [@anthropic2024manyshot].

pyrit/prompt_target/azure_blob_storage_target.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def __init__(
7575
blob_content_type: SupportedContentType = SupportedContentType.PLAIN_TEXT,
7676
max_requests_per_minute: Optional[int] = None,
7777
custom_configuration: Optional[TargetConfiguration] = None,
78-
custom_capabilities: Optional[TargetCapabilities] = None,
7978
) -> None:
8079
"""
8180
Initialize the Azure Blob Storage target.
@@ -90,8 +89,6 @@ def __init__(
9089
max_requests_per_minute (int, Optional): Maximum number of requests per minute.
9190
custom_configuration (TargetConfiguration, Optional): Override the default configuration for
9291
this target instance. Defaults to None.
93-
custom_capabilities (TargetCapabilities, Optional): **Deprecated.** Use
94-
``custom_configuration`` instead. Will be removed in v0.14.0.
9592
"""
9693
self._blob_content_type: str = blob_content_type.value
9794

@@ -106,7 +103,6 @@ def __init__(
106103
endpoint=self._container_url,
107104
max_requests_per_minute=max_requests_per_minute,
108105
custom_configuration=custom_configuration,
109-
custom_capabilities=custom_capabilities,
110106
)
111107

112108
def _build_identifier(self) -> ComponentIdentifier:

pyrit/prompt_target/azure_ml_chat_target.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def __init__(
7070
repetition_penalty: float = 1.0,
7171
max_requests_per_minute: int | None = None,
7272
custom_configuration: TargetConfiguration | None = None,
73-
custom_capabilities: TargetCapabilities | None = None,
7473
**param_kwargs: Any,
7574
) -> None:
7675
"""
@@ -101,8 +100,6 @@ def __init__(
101100
will be capped at the value provided.
102101
custom_configuration (TargetConfiguration | None): Override the default configuration for this target
103102
instance. Useful for targets whose capabilities depend on deployment configuration.
104-
custom_capabilities (TargetCapabilities | None): **Deprecated.** Use
105-
``custom_configuration`` instead. Will be removed in v0.15.0.
106103
**param_kwargs: Additional parameters to pass to the model for generating responses. Example
107104
parameters can be found here: https://huggingface.co/docs/api-inference/tasks/text-generation.
108105
Note that the link above may not be comprehensive, and specific acceptable parameters may be
@@ -155,7 +152,6 @@ def __init__(
155152
endpoint=endpoint_value,
156153
model_name=model_name,
157154
custom_configuration=custom_configuration,
158-
custom_capabilities=custom_capabilities,
159155
)
160156

161157
self._initialize_vars(endpoint=endpoint, api_key=api_key)

pyrit/prompt_target/common/prompt_target.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import abc
55
import logging
6-
import warnings
76
from typing import Any, Union, final
87

98
from pyrit.common.deprecation import print_deprecation_message
@@ -12,7 +11,7 @@
1211
from pyrit.models import Message, MessagePiece
1312
from pyrit.models.json_response_config import _JsonResponseConfig
1413
from pyrit.prompt_target.common.target_capabilities import CapabilityName, TargetCapabilities
15-
from pyrit.prompt_target.common.target_configuration import TargetConfiguration, resolve_configuration_compat
14+
from pyrit.prompt_target.common.target_configuration import TargetConfiguration
1615

1716
logger = logging.getLogger(__name__)
1817

@@ -44,24 +43,6 @@ class PromptTarget(Identifiable):
4443
# constructor parameter, which takes precedence over the class-level value.
4544
_DEFAULT_CONFIGURATION: TargetConfiguration = TargetConfiguration(capabilities=TargetCapabilities())
4645

47-
def __init_subclass__(cls, **kwargs: Any) -> None:
48-
"""
49-
Auto-promote the deprecated ``_DEFAULT_CAPABILITIES`` class attribute.
50-
51-
If a subclass defines ``_DEFAULT_CAPABILITIES`` directly, this hook wraps it
52-
in a ``TargetConfiguration`` and assigns it to ``_DEFAULT_CONFIGURATION``,
53-
emitting a ``DeprecationWarning`` to guide migration.
54-
"""
55-
super().__init_subclass__(**kwargs)
56-
if "_DEFAULT_CAPABILITIES" in cls.__dict__:
57-
warnings.warn(
58-
f"{cls.__name__}._DEFAULT_CAPABILITIES is deprecated and will be removed in v0.14.0. "
59-
"Use _DEFAULT_CONFIGURATION = TargetConfiguration(capabilities=...) instead.",
60-
DeprecationWarning,
61-
stacklevel=2,
62-
)
63-
cls._DEFAULT_CONFIGURATION = TargetConfiguration(capabilities=cls.__dict__["_DEFAULT_CAPABILITIES"])
64-
6546
def __init__(
6647
self,
6748
verbose: bool = False,
@@ -70,7 +51,6 @@ def __init__(
7051
model_name: str = "",
7152
underlying_model: str | None = None,
7253
custom_configuration: TargetConfiguration | None = None,
73-
custom_capabilities: TargetCapabilities | None = None,
7454
) -> None:
7555
"""
7656
Initialize the PromptTarget.
@@ -88,13 +68,7 @@ def __init__(
8868
for this target instance. Useful for targets whose capabilities depend on deployment
8969
configuration (e.g., Playwright, HTTP). If None, uses the class-level
9070
``_DEFAULT_CONFIGURATION``. Defaults to None.
91-
custom_capabilities (TargetCapabilities | None): **Deprecated.** Use
92-
``custom_configuration`` instead. Will be removed in v0.14.0.
9371
"""
94-
custom_configuration = resolve_configuration_compat(
95-
custom_configuration=custom_configuration,
96-
custom_capabilities=custom_capabilities,
97-
)
9872
self._memory = CentralMemory.get_memory_instance()
9973
self._verbose = verbose
10074
self._max_requests_per_minute = max_requests_per_minute
@@ -454,25 +428,6 @@ def get_default_configuration(cls, underlying_model: str | None = None) -> Targe
454428
)
455429
return cls._DEFAULT_CONFIGURATION
456430

457-
@classmethod
458-
def get_default_capabilities(cls, underlying_model: str | None = None) -> TargetCapabilities:
459-
"""
460-
Return the default capabilities for the given model.
461-
462-
**Deprecated.** Use :meth:`get_default_configuration` instead.
463-
Will be removed in v0.14.0.
464-
465-
Returns:
466-
TargetCapabilities: The capabilities for the given model or class default.
467-
"""
468-
warnings.warn(
469-
"get_default_capabilities() is deprecated and will be removed in v0.14.0. "
470-
"Use get_default_configuration() instead.",
471-
DeprecationWarning,
472-
stacklevel=2,
473-
)
474-
return cls.get_default_configuration(underlying_model).capabilities
475-
476431
def _build_identifier(self) -> ComponentIdentifier:
477432
"""
478433
Build the identifier for this target.

pyrit/prompt_target/common/target_configuration.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Licensed under the MIT license.
33

44
import logging
5-
import warnings
65
from collections.abc import Mapping
76
from dataclasses import fields
87
from typing import Any
@@ -20,46 +19,6 @@
2019
logger = logging.getLogger(__name__)
2120

2221

23-
def resolve_configuration_compat(
24-
*,
25-
custom_configuration: "TargetConfiguration | None",
26-
custom_capabilities: TargetCapabilities | None,
27-
) -> "TargetConfiguration | None":
28-
"""
29-
Resolve the deprecated ``custom_capabilities`` parameter.
30-
31-
If the caller supplied the old ``custom_capabilities`` keyword, emit a
32-
:class:`DeprecationWarning` and wrap the value in a
33-
:class:`TargetConfiguration`. Passing both parameters is an error.
34-
35-
Args:
36-
custom_configuration (TargetConfiguration | None): The new-style configuration object.
37-
custom_capabilities (TargetCapabilities | None): The deprecated capabilities object.
38-
39-
Returns:
40-
The resolved :class:`TargetConfiguration`, or *None* when neither
41-
parameter was supplied.
42-
43-
Raises:
44-
ValueError: If both parameters were supplied.
45-
"""
46-
if custom_capabilities is not None and custom_configuration is not None:
47-
raise ValueError(
48-
"Cannot specify both 'custom_capabilities' and 'custom_configuration'. "
49-
"Use 'custom_configuration' only; 'custom_capabilities' is deprecated and"
50-
" will be removed in v0.14.0."
51-
)
52-
if custom_capabilities is not None:
53-
warnings.warn(
54-
"'custom_capabilities' is deprecated and will be removed in v0.14.0. "
55-
"Use 'custom_configuration=TargetConfiguration(capabilities=...)' instead.",
56-
DeprecationWarning,
57-
stacklevel=3,
58-
)
59-
return TargetConfiguration(capabilities=custom_capabilities)
60-
return custom_configuration
61-
62-
6322
# Default policy: RAISE on all adaptable capabilities.
6423
_DEFAULT_POLICY = CapabilityHandlingPolicy()
6524

pyrit/prompt_target/gandalf_target.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from pyrit.identifiers import ComponentIdentifier
1111
from pyrit.models import Message, construct_response_from_request
1212
from pyrit.prompt_target.common.prompt_target import PromptTarget
13-
from pyrit.prompt_target.common.target_capabilities import TargetCapabilities
1413
from pyrit.prompt_target.common.target_configuration import TargetConfiguration
1514
from pyrit.prompt_target.common.utils import limit_requests_per_minute
1615

@@ -46,7 +45,6 @@ def __init__(
4645
level: GandalfLevel,
4746
max_requests_per_minute: Optional[int] = None,
4847
custom_configuration: Optional[TargetConfiguration] = None,
49-
custom_capabilities: Optional[TargetCapabilities] = None,
5048
) -> None:
5149
"""
5250
Initialize the Gandalf target.
@@ -56,17 +54,14 @@ def __init__(
5654
max_requests_per_minute (int, Optional): Number of requests the target can handle per
5755
minute before hitting a rate limit. The number of requests sent to the target
5856
will be capped at the value provided.
59-
custom_configuration (TargetConfiguration, Optional): Override the default configuration for this
57+
custom_configuration (TargetConfiguration, Optional): Override the default configuration for
6058
target instance.
61-
custom_capabilities (TargetCapabilities, Optional): **Deprecated.** Use
62-
``custom_configuration`` instead. Will be removed in v0.14.0.
6359
"""
6460
endpoint = "https://gandalf-api.lakera.ai/api/send-message"
6561
super().__init__(
6662
max_requests_per_minute=max_requests_per_minute,
6763
endpoint=endpoint,
6864
custom_configuration=custom_configuration,
69-
custom_capabilities=custom_capabilities,
7065
)
7166

7267
self._defender = level.value

pyrit/prompt_target/http_target/http_target.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
construct_response_from_request,
1818
)
1919
from pyrit.prompt_target.common.prompt_target import PromptTarget
20-
from pyrit.prompt_target.common.target_capabilities import TargetCapabilities
2120
from pyrit.prompt_target.common.target_configuration import TargetConfiguration
2221
from pyrit.prompt_target.common.utils import limit_requests_per_minute
2322

@@ -43,7 +42,6 @@ def __init__(
4342
client: Optional[httpx.AsyncClient] = None,
4443
model_name: str = "",
4544
custom_configuration: Optional[TargetConfiguration] = None,
46-
custom_capabilities: Optional[TargetCapabilities] = None,
4745
**httpx_client_kwargs: Any,
4846
) -> None:
4947
"""
@@ -61,8 +59,6 @@ def __init__(
6159
model_name (str): The model name. Defaults to empty string.
6260
custom_configuration (TargetConfiguration, Optional): Override the default configuration for
6361
this target instance. Defaults to None.
64-
custom_capabilities (TargetCapabilities, Optional): **Deprecated.** Use
65-
``custom_configuration`` instead. Will be removed in v0.14.0.
6662
**httpx_client_kwargs: Additional keyword arguments for httpx.AsyncClient.
6763
6864
Raises:
@@ -81,7 +77,6 @@ def __init__(
8177
endpoint=endpoint,
8278
model_name=model_name,
8379
custom_configuration=custom_configuration,
84-
custom_capabilities=custom_capabilities,
8580
)
8681
self.http_request = http_request
8782
self.callback_function = callback_function

pyrit/prompt_target/http_target/httpx_api_target.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def __init__(
5050
callback_function: Callable[..., Any] | None = None,
5151
max_requests_per_minute: Optional[int] = None,
5252
custom_configuration: Optional[TargetConfiguration] = None,
53-
custom_capabilities: Optional[TargetCapabilities] = None,
5453
**httpx_client_kwargs: Any,
5554
) -> None:
5655
"""
@@ -71,8 +70,6 @@ def __init__(
7170
custom_configuration (TargetConfiguration, Optional): Override the default configuration for this target
7271
instance.
7372
Defaults to None.
74-
custom_capabilities (TargetCapabilities, Optional): **Deprecated.** Use
75-
``custom_configuration`` instead. Will be removed in v0.14.0.
7673
**httpx_client_kwargs: Additional keyword arguments to pass to the httpx.AsyncClient constructor.
7774
7875
Raises:
@@ -86,7 +83,6 @@ def __init__(
8683
callback_function=callback_function,
8784
max_requests_per_minute=max_requests_per_minute,
8885
custom_configuration=custom_configuration,
89-
custom_capabilities=custom_capabilities,
9086
**httpx_client_kwargs,
9187
)
9288

0 commit comments

Comments
 (0)