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
8 changes: 5 additions & 3 deletions doc/code/datasets/2_seed_programming.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
],
"source": [
"from pyrit.common.path import EXECUTOR_RED_TEAM_PATH, EXECUTOR_SIMULATED_TARGET_PATH\n",
"from pyrit.models import SeedSimulatedConversation\n",
"from pyrit.models import SeedSimulatedConversation, load_next_message_prompt\n",
"\n",
"seed_group = AttackSeedGroup(\n",
" seeds=[\n",
Expand All @@ -488,10 +488,12 @@
" role=\"system\",\n",
" ),\n",
" SeedSimulatedConversation(\n",
" adversarial_chat_system_prompt_path=EXECUTOR_RED_TEAM_PATH / \"naive_crescendo.yaml\",\n",
" adversarial_chat_system_prompt=SeedPrompt.from_yaml_file(EXECUTOR_RED_TEAM_PATH / \"naive_crescendo.yaml\"),\n",
" sequence=1,\n",
" num_turns=4,\n",
" next_message_system_prompt_path=EXECUTOR_SIMULATED_TARGET_PATH / \"direct_next_message.yaml\",\n",
" next_message_system_prompt=load_next_message_prompt(\n",
" EXECUTOR_SIMULATED_TARGET_PATH / \"direct_next_message.yaml\"\n",
" ),\n",
" ),\n",
" ]\n",
")\n",
Expand Down
8 changes: 5 additions & 3 deletions doc/code/datasets/2_seed_programming.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

# %%
from pyrit.common.path import EXECUTOR_RED_TEAM_PATH, EXECUTOR_SIMULATED_TARGET_PATH
from pyrit.models import SeedSimulatedConversation
from pyrit.models import SeedSimulatedConversation, load_next_message_prompt

seed_group = AttackSeedGroup(
seeds=[
Expand All @@ -102,10 +102,12 @@
role="system",
),
SeedSimulatedConversation(
adversarial_chat_system_prompt_path=EXECUTOR_RED_TEAM_PATH / "naive_crescendo.yaml",
adversarial_chat_system_prompt=SeedPrompt.from_yaml_file(EXECUTOR_RED_TEAM_PATH / "naive_crescendo.yaml"),
sequence=1,
num_turns=4,
next_message_system_prompt_path=EXECUTOR_SIMULATED_TARGET_PATH / "direct_next_message.yaml",
next_message_system_prompt=load_next_message_prompt(
EXECUTOR_SIMULATED_TARGET_PATH / "direct_next_message.yaml"
),
),
]
)
Expand Down
16 changes: 9 additions & 7 deletions doc/code/datasets/5_simulated_conversation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"\n",
"## Generating a Simulated Conversation\n",
"\n",
"The function takes an objective, an adversarial chat model, a scorer, and a system prompt path.\n",
"The function takes an objective, an adversarial chat model, a scorer, and a system prompt.\n",
"It runs a `RedTeamingAttack` internally with the adversarial LLM playing both attacker and target\n",
"roles."
]
Expand Down Expand Up @@ -63,7 +63,7 @@
"\n",
"from pyrit.common.path import EXECUTOR_SEED_PROMPT_PATH\n",
"from pyrit.executor.attack import generate_simulated_conversation_async\n",
"from pyrit.models import SeedGroup\n",
"from pyrit.models import SeedGroup, SeedPrompt\n",
"from pyrit.output import output_attack_async\n",
"from pyrit.prompt_target import OpenAIChatTarget\n",
"from pyrit.score import SelfAskRefusalScorer\n",
Expand All @@ -82,7 +82,9 @@
" adversarial_chat=adversarial_chat,\n",
" objective_scorer=objective_scorer,\n",
" num_turns=3,\n",
" adversarial_chat_system_prompt_path=Path(EXECUTOR_SEED_PROMPT_PATH) / \"red_teaming\" / \"naive_crescendo.yaml\",\n",
" adversarial_chat_system_prompt=SeedPrompt.from_yaml_file(\n",
" Path(EXECUTOR_SEED_PROMPT_PATH) / \"red_teaming\" / \"naive_crescendo.yaml\"\n",
" ),\n",
")\n",
"\n",
"print(f\"Generated {len(simulated_result.seed_prompts)} messages\")"
Expand All @@ -100,7 +102,7 @@
"Wrapping the prompts in a `SeedGroup` gives you convenient access to `prepended_conversation`\n",
"(all turns except the last) and `next_message` (the final user message to continue from).\n",
"Note that `next_message` is only populated when the last generated message has role `\"user\"` —\n",
"if you need a final user turn, pass `next_message_system_prompt_path` to the function.\n",
"if you need a final user turn, pass `next_message_system_prompt` to the function.\n",
"\n",
"This replaces the earlier `list[SeedPrompt]` return value. Use `result.seed_prompts` where you\n",
"previously used the returned list."
Expand Down Expand Up @@ -521,9 +523,9 @@
"| `adversarial_chat` | `PromptTarget` | The LLM that generates attack prompts (also plays the simulated target). Must declare `supports_multi_turn=True` and `supports_editable_history=True`. |\n",
"| `objective_scorer` | `TrueFalseScorer` | Evaluates whether the final turn achieved the objective |\n",
"| `num_turns` | `int` | Number of conversation turns to generate (default: 3) |\n",
"| `adversarial_chat_system_prompt_path` | `str \\| Path` | System prompt for the adversarial chat role |\n",
"| `simulated_target_system_prompt_path` | `str \\| Path \\| None` | Optional system prompt for the simulated target role |\n",
"| `next_message_system_prompt_path` | `str \\| Path \\| None` | Optional path to generate a final user message that elicits objective fulfillment |\n",
"| `adversarial_chat_system_prompt` | `SeedPrompt` | System prompt for the adversarial chat role |\n",
"| `simulated_target_system_prompt` | `SeedPrompt \\| None` | Optional system prompt for the simulated target role |\n",
"| `next_message_system_prompt` | `SeedPrompt \\| None` | Optional prompt that generates a final user message eliciting objective fulfillment |\n",
"| `attack_converter_config` | `AttackConverterConfig \\| None` | Optional converter configuration for the attack |\n",
"| `memory_labels` | `dict[str, str] \\| None` | Labels for tracking in memory |\n",
"\n",
Expand Down
16 changes: 9 additions & 7 deletions doc/code/datasets/5_simulated_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#
# ## Generating a Simulated Conversation
#
# The function takes an objective, an adversarial chat model, a scorer, and a system prompt path.
# The function takes an objective, an adversarial chat model, a scorer, and a system prompt.
# It runs a `RedTeamingAttack` internally with the adversarial LLM playing both attacker and target
# roles.

Expand All @@ -36,7 +36,7 @@

from pyrit.common.path import EXECUTOR_SEED_PROMPT_PATH
from pyrit.executor.attack import generate_simulated_conversation_async
from pyrit.models import SeedGroup
from pyrit.models import SeedGroup, SeedPrompt
from pyrit.output import output_attack_async
from pyrit.prompt_target import OpenAIChatTarget
from pyrit.score import SelfAskRefusalScorer
Expand All @@ -55,7 +55,9 @@
adversarial_chat=adversarial_chat,
objective_scorer=objective_scorer,
num_turns=3,
adversarial_chat_system_prompt_path=Path(EXECUTOR_SEED_PROMPT_PATH) / "red_teaming" / "naive_crescendo.yaml",
adversarial_chat_system_prompt=SeedPrompt.from_yaml_file(
Path(EXECUTOR_SEED_PROMPT_PATH) / "red_teaming" / "naive_crescendo.yaml"
),
)

print(f"Generated {len(simulated_result.seed_prompts)} messages")
Expand All @@ -68,7 +70,7 @@
# Wrapping the prompts in a `SeedGroup` gives you convenient access to `prepended_conversation`
# (all turns except the last) and `next_message` (the final user message to continue from).
# Note that `next_message` is only populated when the last generated message has role `"user"` —
# if you need a final user turn, pass `next_message_system_prompt_path` to the function.
# if you need a final user turn, pass `next_message_system_prompt` to the function.
#
# This replaces the earlier `list[SeedPrompt]` return value. Use `result.seed_prompts` where you
# previously used the returned list.
Expand Down Expand Up @@ -130,9 +132,9 @@
# | `adversarial_chat` | `PromptTarget` | The LLM that generates attack prompts (also plays the simulated target). Must declare `supports_multi_turn=True` and `supports_editable_history=True`. |
# | `objective_scorer` | `TrueFalseScorer` | Evaluates whether the final turn achieved the objective |
# | `num_turns` | `int` | Number of conversation turns to generate (default: 3) |
# | `adversarial_chat_system_prompt_path` | `str \| Path` | System prompt for the adversarial chat role |
# | `simulated_target_system_prompt_path` | `str \| Path \| None` | Optional system prompt for the simulated target role |
# | `next_message_system_prompt_path` | `str \| Path \| None` | Optional path to generate a final user message that elicits objective fulfillment |
# | `adversarial_chat_system_prompt` | `SeedPrompt` | System prompt for the adversarial chat role |
# | `simulated_target_system_prompt` | `SeedPrompt \| None` | Optional system prompt for the simulated target role |
# | `next_message_system_prompt` | `SeedPrompt \| None` | Optional prompt that generates a final user message eliciting objective fulfillment |
# | `attack_converter_config` | `AttackConverterConfig \| None` | Optional converter configuration for the attack |
# | `memory_labels` | `dict[str, str] \| None` | Labels for tracking in memory |
#
Expand Down
2 changes: 1 addition & 1 deletion doc/code/memory/3_memory_data_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ All seed types inherit from [`Seed`](../../../pyrit/models/seeds/seed.py), which

- [`SeedObjective`](../../../pyrit/models/seeds/seed_objective.py) — The goal of an attack (e.g., "Generate hate speech content"). Always text. Cannot be a general technique.

- [`SeedSimulatedConversation`](../../../pyrit/models/seeds/seed_simulated_conversation.py) — Configuration for dynamically generating multi-turn conversations. Specifies system prompt paths, number of turns, and sequence offsets. The actual generation happens in the executor layer.
- [`SeedSimulatedConversation`](../../../pyrit/models/seeds/seed_simulated_conversation.py) — Configuration for dynamically generating multi-turn conversations. Carries the adversarial, simulated-target, and next-message system prompts, the number of turns, and sequence offsets. The actual generation happens in the executor layer.

### Seed Groups

Expand Down
6 changes: 3 additions & 3 deletions pyrit/executor/attack/core/attack_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ async def from_seed_group_async(
objective_scorer=objective_scorer,
num_turns=simulated_conversation_config.num_turns,
starting_sequence=simulated_conversation_config.sequence,
adversarial_chat_system_prompt_path=simulated_conversation_config.adversarial_chat_system_prompt_path,
simulated_target_system_prompt_path=simulated_conversation_config.simulated_target_system_prompt_path,
next_message_system_prompt_path=simulated_conversation_config.next_message_system_prompt_path,
adversarial_chat_system_prompt=simulated_conversation_config.adversarial_chat_system_prompt,
simulated_target_system_prompt=simulated_conversation_config.simulated_target_system_prompt,
next_message_system_prompt=simulated_conversation_config.next_message_system_prompt,
)
simulated_prompts = simulated_result.seed_prompts
if "source_conversations" in valid_fields:
Expand Down
Loading
Loading