diff --git a/doc/code/converters/6_selectively_converting.py b/doc/code/converters/6_selectively_converting.py index 1e8df380ad..8cc81262fd 100644 --- a/doc/code/converters/6_selectively_converting.py +++ b/doc/code/converters/6_selectively_converting.py @@ -227,7 +227,6 @@ # `preserve_tokens` can be used to use the output of one converter as the input for the next. This example converts the second half to an angry tone, translates that outpu to spanish, and then changes that output to emoji (but never touches the first half of the message). # %% - first_converter = SelectiveTextConverter( sub_converter=ToneConverter(converter_target=OpenAIChatTarget(), tone="angry"), selection_strategy=WordPositionSelectionStrategy(start_proportion=0.5, end_proportion=1.0), diff --git a/doc/code/datasets/2_seed_programming.ipynb b/doc/code/datasets/2_seed_programming.ipynb index c9b7ff943f..87c85e10af 100644 --- a/doc/code/datasets/2_seed_programming.ipynb +++ b/doc/code/datasets/2_seed_programming.ipynb @@ -11,7 +11,7 @@ "\n", "## Translating from Seeds for Attack Parameters\n", "\n", - "Most [attacks](../executor/0_executor.md) make use of several parameters.\n", + "Most [executors](../executor/0_executor.md) make use of several parameters.\n", "\n", "1. An **objective** - what you're trying to achieve\n", "2. A **next_message** (optional) - the next message to send to the target\n", diff --git a/doc/code/scenarios/2_custom_scenario_parameters.ipynb b/doc/code/scenarios/2_custom_scenario_parameters.ipynb index f721a4b70a..19b5559165 100644 --- a/doc/code/scenarios/2_custom_scenario_parameters.ipynb +++ b/doc/code/scenarios/2_custom_scenario_parameters.ipynb @@ -211,7 +211,7 @@ "\n", "Scenario-declared flags don't appear in `pyrit_scan run --help`\n", "(that shows only the built-in run options); use `list-scenarios` to discover\n", - "a scenario's parameters.\n", + "the full list of a scenario's parameters.\n", "\n", "## Discovering parameters via `list-scenarios`\n", "\n", diff --git a/doc/code/targets/10_1_playwright_target.ipynb b/doc/code/targets/10_1_playwright_target.ipynb index 777743a6d3..909d8ae181 100644 --- a/doc/code/targets/10_1_playwright_target.ipynb +++ b/doc/code/targets/10_1_playwright_target.ipynb @@ -63,6 +63,8 @@ "from urllib.error import URLError\n", "from urllib.request import urlopen\n", "\n", + "from pyrit.output import output_attack_async\n", + "\n", "\n", "def start_flask_app() -> subprocess.Popen:\n", " # Get the notebook's directory\n", @@ -206,7 +208,7 @@ "import asyncio\n", "import sys\n", "\n", - "from pyrit.output import output_attack_async\n", + "from pyrit.executor.attack import PromptSendingAttack\n", "\n", "if sys.platform == \"win32\":\n", " asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())\n", diff --git a/doc/code/targets/10_1_playwright_target.py b/doc/code/targets/10_1_playwright_target.py index fae4437043..dfb3e44108 100644 --- a/doc/code/targets/10_1_playwright_target.py +++ b/doc/code/targets/10_1_playwright_target.py @@ -23,6 +23,7 @@ # To run the Flask app, you also must [download](https://ollama.com/download) and run Ollama, making sure the flask is using a correct model. For example, `ollama run llama3.2:1b` runs the Llama 3.2 1B model. # # Additionally, you need to install playwright by executing `playwright install`. + # %% [markdown] # ## Example: Interacting with a Web Application using `PlaywrightTarget` # diff --git a/doc/code/targets/10_3_websocket_copilot_target.ipynb b/doc/code/targets/10_3_websocket_copilot_target.ipynb index 2c51f23dff..41ba5dc18c 100644 --- a/doc/code/targets/10_3_websocket_copilot_target.ipynb +++ b/doc/code/targets/10_3_websocket_copilot_target.ipynb @@ -58,6 +58,7 @@ ], "source": [ "# type: ignore\n", + "from pyrit.executor.attack import PromptSendingAttack\n", "from pyrit.output import output_attack_async\n", "from pyrit.prompt_target import WebSocketCopilotTarget\n", "from pyrit.setup import IN_MEMORY, initialize_pyrit_async\n", @@ -82,7 +83,7 @@ "\n", "The `WebSocketCopilotTarget` supports multi-turn conversations by leveraging Copilot's server-side conversation management. It automatically generates consistent `session_id` and `conversation_id` values for each PyRIT conversation, enabling Copilot to maintain context across multiple turns.\n", "\n", - " \"However, this target does not support setting a system prompt nor modifying conversation history. As a result, it cannot be used with attack strategies that require altering prior messages (such as PAIR, TAP, or flip attack) or in contexts where a chat-style target (one that declares `supports_multi_turn=True` and `supports_editable_history=True`) is required.\\n\",\n", + "However, this target does not support setting a system prompt nor modifying conversation history. As a result, it cannot be used with attack strategies that require altering prior messages (such as PAIR, TAP, or flip attack) or in contexts where a chat-style target (one that declares `supports_multi_turn=True` and `supports_editable_history=True`) is required.\n", "\n", "Here is a simple multi-turn conversation example:" ] @@ -163,6 +164,7 @@ } ], "source": [ + "from pyrit.executor.attack import MultiPromptSendingAttack\n", "from pyrit.models import Message\n", "from pyrit.output import output_attack_async\n", "from pyrit.prompt_target import WebSocketCopilotTarget\n", @@ -249,6 +251,7 @@ ], "source": [ "from pyrit.auth import ManualCopilotAuthenticator\n", + "from pyrit.executor.attack import PromptSendingAttack\n", "from pyrit.output import output_attack_async\n", "from pyrit.prompt_target import WebSocketCopilotTarget\n", "from pyrit.setup import IN_MEMORY, initialize_pyrit_async\n", @@ -355,6 +358,7 @@ "source": [ "from pathlib import Path\n", "\n", + "from pyrit.executor.attack import PromptSendingAttack\n", "from pyrit.models import Message, MessagePiece\n", "from pyrit.output import output_attack_async\n", "from pyrit.prompt_target import WebSocketCopilotTarget\n", diff --git a/doc/code/targets/10_3_websocket_copilot_target.py b/doc/code/targets/10_3_websocket_copilot_target.py index 9db8fe621b..b8cbb7f100 100644 --- a/doc/code/targets/10_3_websocket_copilot_target.py +++ b/doc/code/targets/10_3_websocket_copilot_target.py @@ -17,10 +17,12 @@ # - Playwright installed: `pip install playwright && playwright install chromium` # # Some environments are not suited for automated authentication (e.g. they have security policies with retrieving tokens or have MFA). See the [Alternative Authentication](#alternative-authentication-with-manualcopilotauthenticator) section below. + # %% [markdown] # ## Basic Usage with `PromptSendingAttack` # # The simplest way to interact with the `WebSocketCopilotTarget` is through the `PromptSendingAttack` class. + # %% # type: ignore from pyrit.executor.attack import PromptSendingAttack @@ -37,6 +39,8 @@ result = await attack.execute_async(objective=objective) await output_attack_async(result) + +# %% [markdown] # ## Multi-Turn Conversations # # The `WebSocketCopilotTarget` supports multi-turn conversations by leveraging Copilot's server-side conversation management. It automatically generates consistent `session_id` and `conversation_id` values for each PyRIT conversation, enabling Copilot to maintain context across multiple turns. @@ -48,6 +52,7 @@ # %% from pyrit.executor.attack import MultiPromptSendingAttack from pyrit.models import Message +from pyrit.output import output_attack_async from pyrit.prompt_target import WebSocketCopilotTarget from pyrit.setup import IN_MEMORY, initialize_pyrit_async @@ -71,6 +76,8 @@ ) await output_attack_async(result) + +# %% [markdown] # ## Alternative Authentication with `ManualCopilotAuthenticator` # # If browser automation is not suitable for your environment, you can use the `ManualCopilotAuthenticator` instead. This authenticator accepts a pre-obtained access token that you can extract from your browser's DevTools. @@ -90,6 +97,7 @@ # %% from pyrit.auth import ManualCopilotAuthenticator from pyrit.executor.attack import PromptSendingAttack +from pyrit.output import output_attack_async from pyrit.prompt_target import WebSocketCopilotTarget from pyrit.setup import IN_MEMORY, initialize_pyrit_async @@ -106,6 +114,8 @@ result_manual = await attack_manual.execute_async(objective="Hello! Who are you?") await output_attack_async(result_manual) + +# %% [markdown] # ## Multimodal Support (Text and Images) # # The `WebSocketCopilotTarget` supports multimodal input, allowing you to send both text and images in a single message. Images are automatically uploaded to Copilot's file service and referenced in the conversation using the same process as the Copilot web interface. @@ -117,6 +127,7 @@ from pyrit.executor.attack import PromptSendingAttack from pyrit.models import Message, MessagePiece +from pyrit.output import output_attack_async from pyrit.prompt_target import WebSocketCopilotTarget from pyrit.setup import IN_MEMORY, initialize_pyrit_async diff --git a/doc/getting_started/troubleshooting/deploy_hf_model_aml.py b/doc/getting_started/troubleshooting/deploy_hf_model_aml.py index b6fa4a1e67..5f219521ff 100644 --- a/doc/getting_started/troubleshooting/deploy_hf_model_aml.py +++ b/doc/getting_started/troubleshooting/deploy_hf_model_aml.py @@ -106,7 +106,6 @@ # Set up the `DefaultAzureCredential` for seamless authentication with Azure services. This method should handle most authentication scenarios. If you encounter issues, refer to the [Azure Identity documentation](https://docs.microsoft.com/en-us/python/api/azure-identity/azure.identity?view=azure-python) for alternative credentials. # # %% - from azure.ai.ml import MLClient from azure.core.exceptions import ResourceNotFoundError from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential