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
1 change: 0 additions & 1 deletion doc/code/converters/6_selectively_converting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion doc/code/datasets/2_seed_programming.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion doc/code/scenarios/2_custom_scenario_parameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"\n",
"Scenario-declared flags don't appear in `pyrit_scan run <scenario> --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",
Expand Down
4 changes: 3 additions & 1 deletion doc/code/targets/10_1_playwright_target.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions doc/code/targets/10_1_playwright_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
#
Expand Down
6 changes: 5 additions & 1 deletion doc/code/targets/10_3_websocket_copilot_target.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:"
]
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -249,6 +251,7 @@
],
"source": [
"from pyrit.auth import ManualCopilotAuthenticator\n",
"from pyrit.executor.attack import PromptSendingAttack\n",
Comment thread
romanlutz marked this conversation as resolved.
"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",
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions doc/code/targets/10_3_websocket_copilot_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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

Expand All @@ -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.
Expand All @@ -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

Expand All @@ -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.
Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion doc/getting_started/troubleshooting/deploy_hf_model_aml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down