Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions pyrit/cli/pyrit_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

from pyrit.cli import _banner as banner
from pyrit.cli._cli_args import merge_config_scenario_args
from pyrit.common.deprecation import print_deprecation_message
from pyrit.registry import ScenarioRegistry


Expand Down Expand Up @@ -73,7 +72,6 @@ def __init__(
initializer_names: Optional[list[Any]] = None,
env_files: Optional[list[Path]] = None,
log_level: Optional[int] = None,
context: Optional[frontend_core.FrontendCore] = None,
) -> None:
"""
Initialize the PyRIT shell.
Expand All @@ -90,12 +88,6 @@ def __init__(
initializer_names (Optional[list[Any]]): Initializer entries (names or dicts).
env_files (Optional[list[Path]]): Environment file paths to load in order.
log_level (Optional[int]): Logging level constant (e.g., ``logging.WARNING``).
context (Optional[frontend_core.FrontendCore]): Deprecated. Pre-created FrontendCore
context. Use the individual keyword arguments instead.

Raises:
ValueError: If ``context`` is provided together with any other
FrontendCore keyword arguments.
"""
super().__init__()
self._no_animation = no_animation
Expand All @@ -112,21 +104,6 @@ def __init__(
if v is not None
}

if context is not None:
if self._context_kwargs:
raise ValueError(
"Cannot pass 'context' together with FrontendCore keyword arguments "
f"({', '.join(self._context_kwargs)}). Use one or the other."
)
print_deprecation_message(
old_item="PyRITShell(context=...)",
new_item="PyRITShell(database=..., log_level=..., ...)",
removed_in="0.14.0",
)
self._deprecated_context: frontend_core.FrontendCore | None = context
else:
self._deprecated_context = None

# Track scenario execution history: list of (command_string, ScenarioResult) tuples
self._scenario_history: list[tuple[str, ScenarioResult]] = []

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

self._fc = fc
if self._deprecated_context is not None:
self.context = self._deprecated_context
else:
self.context = fc.FrontendCore(**self._context_kwargs)
self.context = fc.FrontendCore(**self._context_kwargs)
self.default_log_level = self.context._log_level
asyncio.run(self.context.initialize_async())
except BaseException as exc:
Expand Down
16 changes: 0 additions & 16 deletions pyrit/executor/attack/single_turn/many_shot_jailbreak.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Any, Optional

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


def fetch_many_shot_jailbreaking_dataset() -> list[dict[str, str]]:
"""
Load many-shot jailbreaking examples (deprecated, use load_many_shot_jailbreaking_dataset).

Returns:
list[dict[str, str]]: A list of many-shot jailbreaking examples.
"""
print_deprecation_message(
old_item=fetch_many_shot_jailbreaking_dataset,
new_item=load_many_shot_jailbreaking_dataset,
removed_in="0.14.0",
)
return load_many_shot_jailbreaking_dataset()


class ManyShotJailbreakAttack(PromptSendingAttack):
"""
Implement the Many Shot Jailbreak method [@anthropic2024manyshot].
Expand Down
4 changes: 0 additions & 4 deletions pyrit/prompt_target/azure_blob_storage_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def __init__(
blob_content_type: SupportedContentType = SupportedContentType.PLAIN_TEXT,
max_requests_per_minute: Optional[int] = None,
custom_configuration: Optional[TargetConfiguration] = None,
custom_capabilities: Optional[TargetCapabilities] = None,
) -> None:
"""
Initialize the Azure Blob Storage target.
Expand All @@ -90,8 +89,6 @@ def __init__(
max_requests_per_minute (int, Optional): Maximum number of requests per minute.
custom_configuration (TargetConfiguration, Optional): Override the default configuration for
this target instance. Defaults to None.
custom_capabilities (TargetCapabilities, Optional): **Deprecated.** Use
``custom_configuration`` instead. Will be removed in v0.14.0.
"""
self._blob_content_type: str = blob_content_type.value

Expand All @@ -106,7 +103,6 @@ def __init__(
endpoint=self._container_url,
max_requests_per_minute=max_requests_per_minute,
custom_configuration=custom_configuration,
custom_capabilities=custom_capabilities,
)

def _build_identifier(self) -> ComponentIdentifier:
Expand Down
4 changes: 0 additions & 4 deletions pyrit/prompt_target/azure_ml_chat_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def __init__(
repetition_penalty: float = 1.0,
max_requests_per_minute: int | None = None,
custom_configuration: TargetConfiguration | None = None,
custom_capabilities: TargetCapabilities | None = None,
**param_kwargs: Any,
) -> None:
"""
Expand Down Expand Up @@ -101,8 +100,6 @@ def __init__(
will be capped at the value provided.
custom_configuration (TargetConfiguration | None): Override the default configuration for this target
instance. Useful for targets whose capabilities depend on deployment configuration.
custom_capabilities (TargetCapabilities | None): **Deprecated.** Use
``custom_configuration`` instead. Will be removed in v0.15.0.
**param_kwargs: Additional parameters to pass to the model for generating responses. Example
parameters can be found here: https://huggingface.co/docs/api-inference/tasks/text-generation.
Note that the link above may not be comprehensive, and specific acceptable parameters may be
Expand Down Expand Up @@ -155,7 +152,6 @@ def __init__(
endpoint=endpoint_value,
model_name=model_name,
custom_configuration=custom_configuration,
custom_capabilities=custom_capabilities,
)

self._initialize_vars(endpoint=endpoint, api_key=api_key)
Expand Down
47 changes: 1 addition & 46 deletions pyrit/prompt_target/common/prompt_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import abc
import logging
import warnings
from typing import Any, Union, final

from pyrit.common.deprecation import print_deprecation_message
Expand All @@ -12,7 +11,7 @@
from pyrit.models import Message, MessagePiece
from pyrit.models.json_response_config import _JsonResponseConfig
from pyrit.prompt_target.common.target_capabilities import CapabilityName, TargetCapabilities
from pyrit.prompt_target.common.target_configuration import TargetConfiguration, resolve_configuration_compat
from pyrit.prompt_target.common.target_configuration import TargetConfiguration

logger = logging.getLogger(__name__)

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

def __init_subclass__(cls, **kwargs: Any) -> None:
"""
Auto-promote the deprecated ``_DEFAULT_CAPABILITIES`` class attribute.

If a subclass defines ``_DEFAULT_CAPABILITIES`` directly, this hook wraps it
in a ``TargetConfiguration`` and assigns it to ``_DEFAULT_CONFIGURATION``,
emitting a ``DeprecationWarning`` to guide migration.
"""
super().__init_subclass__(**kwargs)
if "_DEFAULT_CAPABILITIES" in cls.__dict__:
warnings.warn(
f"{cls.__name__}._DEFAULT_CAPABILITIES is deprecated and will be removed in v0.14.0. "
"Use _DEFAULT_CONFIGURATION = TargetConfiguration(capabilities=...) instead.",
DeprecationWarning,
stacklevel=2,
)
cls._DEFAULT_CONFIGURATION = TargetConfiguration(capabilities=cls.__dict__["_DEFAULT_CAPABILITIES"])

def __init__(
self,
verbose: bool = False,
Expand All @@ -70,7 +51,6 @@ def __init__(
model_name: str = "",
underlying_model: str | None = None,
custom_configuration: TargetConfiguration | None = None,
custom_capabilities: TargetCapabilities | None = None,
) -> None:
"""
Initialize the PromptTarget.
Expand All @@ -88,13 +68,7 @@ def __init__(
for this target instance. Useful for targets whose capabilities depend on deployment
configuration (e.g., Playwright, HTTP). If None, uses the class-level
``_DEFAULT_CONFIGURATION``. Defaults to None.
custom_capabilities (TargetCapabilities | None): **Deprecated.** Use
``custom_configuration`` instead. Will be removed in v0.14.0.
"""
custom_configuration = resolve_configuration_compat(
custom_configuration=custom_configuration,
custom_capabilities=custom_capabilities,
)
self._memory = CentralMemory.get_memory_instance()
self._verbose = verbose
self._max_requests_per_minute = max_requests_per_minute
Expand Down Expand Up @@ -454,25 +428,6 @@ def get_default_configuration(cls, underlying_model: str | None = None) -> Targe
)
return cls._DEFAULT_CONFIGURATION

@classmethod
def get_default_capabilities(cls, underlying_model: str | None = None) -> TargetCapabilities:
"""
Return the default capabilities for the given model.

**Deprecated.** Use :meth:`get_default_configuration` instead.
Will be removed in v0.14.0.

Returns:
TargetCapabilities: The capabilities for the given model or class default.
"""
warnings.warn(
"get_default_capabilities() is deprecated and will be removed in v0.14.0. "
"Use get_default_configuration() instead.",
DeprecationWarning,
stacklevel=2,
)
return cls.get_default_configuration(underlying_model).capabilities

def _build_identifier(self) -> ComponentIdentifier:
"""
Build the identifier for this target.
Expand Down
41 changes: 0 additions & 41 deletions pyrit/prompt_target/common/target_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under the MIT license.

import logging
import warnings
from collections.abc import Mapping
from dataclasses import fields
from typing import Any
Expand All @@ -20,46 +19,6 @@
logger = logging.getLogger(__name__)


def resolve_configuration_compat(
*,
custom_configuration: "TargetConfiguration | None",
custom_capabilities: TargetCapabilities | None,
) -> "TargetConfiguration | None":
"""
Resolve the deprecated ``custom_capabilities`` parameter.

If the caller supplied the old ``custom_capabilities`` keyword, emit a
:class:`DeprecationWarning` and wrap the value in a
:class:`TargetConfiguration`. Passing both parameters is an error.

Args:
custom_configuration (TargetConfiguration | None): The new-style configuration object.
custom_capabilities (TargetCapabilities | None): The deprecated capabilities object.

Returns:
The resolved :class:`TargetConfiguration`, or *None* when neither
parameter was supplied.

Raises:
ValueError: If both parameters were supplied.
"""
if custom_capabilities is not None and custom_configuration is not None:
raise ValueError(
"Cannot specify both 'custom_capabilities' and 'custom_configuration'. "
"Use 'custom_configuration' only; 'custom_capabilities' is deprecated and"
" will be removed in v0.14.0."
)
if custom_capabilities is not None:
warnings.warn(
"'custom_capabilities' is deprecated and will be removed in v0.14.0. "
"Use 'custom_configuration=TargetConfiguration(capabilities=...)' instead.",
DeprecationWarning,
stacklevel=3,
)
return TargetConfiguration(capabilities=custom_capabilities)
return custom_configuration


# Default policy: RAISE on all adaptable capabilities.
_DEFAULT_POLICY = CapabilityHandlingPolicy()

Expand Down
7 changes: 1 addition & 6 deletions pyrit/prompt_target/gandalf_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pyrit.identifiers import ComponentIdentifier
from pyrit.models import Message, construct_response_from_request
from pyrit.prompt_target.common.prompt_target import PromptTarget
from pyrit.prompt_target.common.target_capabilities import TargetCapabilities
from pyrit.prompt_target.common.target_configuration import TargetConfiguration
from pyrit.prompt_target.common.utils import limit_requests_per_minute

Expand Down Expand Up @@ -46,7 +45,6 @@ def __init__(
level: GandalfLevel,
max_requests_per_minute: Optional[int] = None,
custom_configuration: Optional[TargetConfiguration] = None,
custom_capabilities: Optional[TargetCapabilities] = None,
) -> None:
"""
Initialize the Gandalf target.
Expand All @@ -56,17 +54,14 @@ def __init__(
max_requests_per_minute (int, Optional): Number of requests the target can handle per
minute before hitting a rate limit. The number of requests sent to the target
will be capped at the value provided.
custom_configuration (TargetConfiguration, Optional): Override the default configuration for this
custom_configuration (TargetConfiguration, Optional): Override the default configuration for
target instance.
custom_capabilities (TargetCapabilities, Optional): **Deprecated.** Use
``custom_configuration`` instead. Will be removed in v0.14.0.
"""
endpoint = "https://gandalf-api.lakera.ai/api/send-message"
super().__init__(
max_requests_per_minute=max_requests_per_minute,
endpoint=endpoint,
custom_configuration=custom_configuration,
custom_capabilities=custom_capabilities,
)

self._defender = level.value
Expand Down
5 changes: 0 additions & 5 deletions pyrit/prompt_target/http_target/http_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
construct_response_from_request,
)
from pyrit.prompt_target.common.prompt_target import PromptTarget
from pyrit.prompt_target.common.target_capabilities import TargetCapabilities
from pyrit.prompt_target.common.target_configuration import TargetConfiguration
from pyrit.prompt_target.common.utils import limit_requests_per_minute

Expand All @@ -43,7 +42,6 @@ def __init__(
client: Optional[httpx.AsyncClient] = None,
model_name: str = "",
custom_configuration: Optional[TargetConfiguration] = None,
custom_capabilities: Optional[TargetCapabilities] = None,
**httpx_client_kwargs: Any,
) -> None:
"""
Expand All @@ -61,8 +59,6 @@ def __init__(
model_name (str): The model name. Defaults to empty string.
custom_configuration (TargetConfiguration, Optional): Override the default configuration for
this target instance. Defaults to None.
custom_capabilities (TargetCapabilities, Optional): **Deprecated.** Use
``custom_configuration`` instead. Will be removed in v0.14.0.
**httpx_client_kwargs: Additional keyword arguments for httpx.AsyncClient.

Raises:
Expand All @@ -81,7 +77,6 @@ def __init__(
endpoint=endpoint,
model_name=model_name,
custom_configuration=custom_configuration,
custom_capabilities=custom_capabilities,
)
self.http_request = http_request
self.callback_function = callback_function
Expand Down
4 changes: 0 additions & 4 deletions pyrit/prompt_target/http_target/httpx_api_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def __init__(
callback_function: Callable[..., Any] | None = None,
max_requests_per_minute: Optional[int] = None,
custom_configuration: Optional[TargetConfiguration] = None,
custom_capabilities: Optional[TargetCapabilities] = None,
**httpx_client_kwargs: Any,
) -> None:
"""
Expand All @@ -71,8 +70,6 @@ def __init__(
custom_configuration (TargetConfiguration, Optional): Override the default configuration for this target
instance.
Defaults to None.
custom_capabilities (TargetCapabilities, Optional): **Deprecated.** Use
``custom_configuration`` instead. Will be removed in v0.14.0.
**httpx_client_kwargs: Additional keyword arguments to pass to the httpx.AsyncClient constructor.

Raises:
Expand All @@ -86,7 +83,6 @@ def __init__(
callback_function=callback_function,
max_requests_per_minute=max_requests_per_minute,
custom_configuration=custom_configuration,
custom_capabilities=custom_capabilities,
**httpx_client_kwargs,
)

Expand Down
Loading
Loading