Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/instructions/scenarios.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ The default implementation:

Techniques are described by `AttackTechniqueFactory` instances rather than a separate spec
dataclass. The canonical catalog lives in
`pyrit.setup.initializers.components.scenario_techniques` (`build_scenario_technique_factories()`)
and is loaded into the registry by `ScenarioTechniqueInitializer`.
`pyrit.setup.initializers.techniques` (`build_technique_factories()`)
and is loaded into the registry by `TechniqueInitializer`.

```python
from pyrit.scenario.core.attack_technique_factory import AttackTechniqueFactory
Expand Down Expand Up @@ -201,7 +201,7 @@ Key points:

```python
registry = AttackTechniqueRegistry.get_registry_singleton()
registry.register_from_factories(build_scenario_technique_factories())
registry.register_from_factories(build_technique_factories())
```

`register_from_factories` reads `factory.strategy_tags` to populate the per-entry tags used
Expand Down
16 changes: 7 additions & 9 deletions .pyrit_conf_example
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ memory_db_type: sqlite
# ------------
# List of built-in initializers to run during PyRIT initialization.
# Initializers configure default values for converters, scorers, and targets.
# Names are normalized to snake_case (e.g., "SimpleInitializer" -> "simple").
# Names are normalized to snake_case (e.g., "TargetInitializer" -> "target").
#
# Available initializers:
# - simple: Basic OpenAI configuration (requires OPENAI_CHAT_* env vars)
# - airt: AI Red Team setup with Azure OpenAI (requires AZURE_OPENAI_* env vars)
# - target: Registers available prompt targets into the TargetRegistry
# - scorer: Registers pre-configured scorers into the ScorerRegistry
# - load_default_datasets: Loads default datasets for all registered scenarios
# - objective_list: Sets default objectives for scenarios
# - technique: Registers attack techniques into the AttackTechniqueRegistry
# - load_default_datasets: Loads datasets into memory so scenarios can run
# - preload_scenario_metadata: Preloads scenario metadata into the registry
#
# Each initializer can be specified as:
# - A simple string (name only)
Expand All @@ -38,22 +37,21 @@ memory_db_type: sqlite
#
# Example:
# initializers:
# - simple
# - scorer
# - name: target
# args:
# tags:
# - default
# - scorer
initializers:
- name: simple
- name: scenario_technique
- name: load_default_datasets
- name: target
args:
tags:
- default
- scorer
- name: scorer
- name: technique
- name: load_default_datasets

# Default Scenario
# ----------------
Expand Down
10 changes: 5 additions & 5 deletions doc/code/scenarios/0_attack_techniques.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"Techniques are registered into a singleton\n",
"[`AttackTechniqueRegistry`](../../../pyrit/registry/object_registries/attack_technique_registry.py)\n",
"by an **initializer**. The canonical catalog lives in\n",
"[`ScenarioTechniqueInitializer`](../../../pyrit/setup/initializers/components/scenario_techniques.py),\n",
"[`TechniqueInitializer`](../../../pyrit/setup/initializers/techniques/technique_initializer.py),\n",
"which registers a flat list of\n",
"[`AttackTechniqueFactory`](../../../pyrit/scenario/core/attack_technique_factory.py) instances.\n",
"Each factory is self-describing — it knows its `name`, the attack class it builds, its tags, and\n",
Expand Down Expand Up @@ -94,10 +94,10 @@
"\n",
"from pyrit.registry.object_registries.attack_technique_registry import AttackTechniqueRegistry\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit_async\n",
"from pyrit.setup.initializers.components import ScenarioTechniqueInitializer\n",
"from pyrit.setup.initializers.techniques import TechniqueInitializer\n",
"\n",
"await initialize_pyrit_async(memory_db_type=IN_MEMORY, silent=True) # type: ignore\n",
"await ScenarioTechniqueInitializer().initialize_async() # type: ignore\n",
"await TechniqueInitializer().initialize_async() # type: ignore\n",
"\n",
"factories = AttackTechniqueRegistry.get_registry_singleton().get_factories()\n",
"\n",
Expand Down Expand Up @@ -141,7 +141,7 @@
"\n",
"```mermaid\n",
"flowchart LR\n",
" I[\"ScenarioTechniqueInitializer\"] -->|registers factories| R[\"AttackTechniqueRegistry\"]\n",
" I[\"TechniqueInitializer\"] -->|registers factories| R[\"AttackTechniqueRegistry\"]\n",
" R -->|builds enum + tags| S[\"ScenarioStrategy\"]\n",
" S -->|name / tag / composite| Sc[\"Scenario\"]\n",
" R -->|create with target + scorer| T[\"AttackTechnique<br/>(attack + seeds)\"]\n",
Expand Down Expand Up @@ -184,7 +184,7 @@
")\n",
"```\n",
"\n",
"Wrap registration in a `PyRITInitializer` (as `ScenarioTechniqueInitializer` does) when you want it\n",
"Wrap registration in a `PyRITInitializer` (as `TechniqueInitializer` does) when you want it\n",
"to run as part of standard setup. Any scenario built afterwards will see `my_role_play` as a\n",
"selectable strategy."
]
Expand Down
10 changes: 5 additions & 5 deletions doc/code/scenarios/0_attack_techniques.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# Techniques are registered into a singleton
# [`AttackTechniqueRegistry`](../../../pyrit/registry/object_registries/attack_technique_registry.py)
# by an **initializer**. The canonical catalog lives in
# [`ScenarioTechniqueInitializer`](../../../pyrit/setup/initializers/components/scenario_techniques.py),
# [`TechniqueInitializer`](../../../pyrit/setup/initializers/techniques/technique_initializer.py),
# which registers a flat list of
# [`AttackTechniqueFactory`](../../../pyrit/scenario/core/attack_technique_factory.py) instances.
# Each factory is self-describing — it knows its `name`, the attack class it builds, its tags, and
Expand All @@ -67,10 +67,10 @@

from pyrit.registry.object_registries.attack_technique_registry import AttackTechniqueRegistry
from pyrit.setup import IN_MEMORY, initialize_pyrit_async
from pyrit.setup.initializers.components import ScenarioTechniqueInitializer
from pyrit.setup.initializers.techniques import TechniqueInitializer

await initialize_pyrit_async(memory_db_type=IN_MEMORY, silent=True) # type: ignore
await ScenarioTechniqueInitializer().initialize_async() # type: ignore
await TechniqueInitializer().initialize_async() # type: ignore

factories = AttackTechniqueRegistry.get_registry_singleton().get_factories()

Expand Down Expand Up @@ -109,7 +109,7 @@
#
# ```mermaid
# flowchart LR
# I["ScenarioTechniqueInitializer"] -->|registers factories| R["AttackTechniqueRegistry"]
# I["TechniqueInitializer"] -->|registers factories| R["AttackTechniqueRegistry"]
# R -->|builds enum + tags| S["ScenarioStrategy"]
# S -->|name / tag / composite| Sc["Scenario"]
# R -->|create with target + scorer| T["AttackTechnique<br/>(attack + seeds)"]
Expand Down Expand Up @@ -147,6 +147,6 @@
# )
# ```
#
# Wrap registration in a `PyRITInitializer` (as `ScenarioTechniqueInitializer` does) when you want it
# Wrap registration in a `PyRITInitializer` (as `TechniqueInitializer` does) when you want it
# to run as part of standard setup. Any scenario built afterwards will see `my_role_play` as a
# selectable strategy.
4 changes: 2 additions & 2 deletions doc/code/scenarios/0_scenarios.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@
")\n",
"from pyrit.score.true_false.true_false_scorer import TrueFalseScorer\n",
"from pyrit.setup import initialize_pyrit_async\n",
"from pyrit.setup.initializers.components import ScenarioTechniqueInitializer\n",
"from pyrit.setup.initializers.techniques import TechniqueInitializer\n",
"\n",
"await initialize_pyrit_async(memory_db_type=\"InMemory\") # type: ignore [top-level-await]\n",
"await ScenarioTechniqueInitializer().initialize_async() # type: ignore [top-level-await]\n",
"await TechniqueInitializer().initialize_async() # type: ignore [top-level-await]\n",
"\n",
"\n",
"class MyStrategy(ScenarioStrategy):\n",
Expand Down
4 changes: 2 additions & 2 deletions doc/code/scenarios/0_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@
)
from pyrit.score.true_false.true_false_scorer import TrueFalseScorer
from pyrit.setup import initialize_pyrit_async
from pyrit.setup.initializers.components import ScenarioTechniqueInitializer
from pyrit.setup.initializers.techniques import TechniqueInitializer

await initialize_pyrit_async(memory_db_type="InMemory") # type: ignore [top-level-await]
await ScenarioTechniqueInitializer().initialize_async() # type: ignore [top-level-await]
await TechniqueInitializer().initialize_async() # type: ignore [top-level-await]


class MyStrategy(ScenarioStrategy):
Expand Down
4 changes: 2 additions & 2 deletions doc/code/scenarios/2_custom_scenario_parameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
"source": [
"from pyrit.scenario.airt.scam import Scam\n",
"from pyrit.setup import initialize_pyrit_async\n",
"from pyrit.setup.initializers.components import ScenarioTechniqueInitializer\n",
"from pyrit.setup.initializers.techniques import TechniqueInitializer\n",
"\n",
"await initialize_pyrit_async(memory_db_type=\"InMemory\") # type: ignore [top-level-await]\n",
"await ScenarioTechniqueInitializer().initialize_async() # type: ignore [top-level-await]\n",
"await TechniqueInitializer().initialize_async() # type: ignore [top-level-await]\n",
"\n",
"for param in Scam.supported_parameters():\n",
" print(param)"
Expand Down
4 changes: 2 additions & 2 deletions doc/code/scenarios/2_custom_scenario_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
# %%
from pyrit.scenario.airt.scam import Scam
from pyrit.setup import initialize_pyrit_async
from pyrit.setup.initializers.components import ScenarioTechniqueInitializer
from pyrit.setup.initializers.techniques import TechniqueInitializer

await initialize_pyrit_async(memory_db_type="InMemory") # type: ignore [top-level-await]
await ScenarioTechniqueInitializer().initialize_async() # type: ignore [top-level-await]
await TechniqueInitializer().initialize_async() # type: ignore [top-level-await]

for param in Scam.supported_parameters():
print(param)
Expand Down
6 changes: 3 additions & 3 deletions doc/code/setup/0_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ PyRIT setup involves three main components to get you started with security test

## Quick Start

For the fastest setup, use the `SimpleInitializer` which requires only basic OpenAI environment variables:
For the fastest setup, use `TargetInitializer` and `ScorerInitializer`, which require only basic OpenAI environment variables:

```python
from pyrit.setup import initialize_pyrit_async
from pyrit.setup.initializers import SimpleInitializer
from pyrit.setup.initializers import ScorerInitializer, TargetInitializer

await initialize_pyrit_async(memory_db_type="InMemory", initializers=[SimpleInitializer()])
await initialize_pyrit_async(memory_db_type="InMemory", initializers=[TargetInitializer(), ScorerInitializer()])
```

This configuration allows you to run most PyRIT notebooks immediately.
Expand Down
27 changes: 13 additions & 14 deletions doc/code/setup/1_configuration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"source": [
"## Simple Example\n",
"\n",
"This section goes into each of the three steps mentioned earlier. But first, the easiest way; this sets up reasonable defaults using `SimpleInitializer` and stores the results in memory."
"This section goes into each of the three steps mentioned earlier. But first, the easiest way; this sets up reasonable defaults using `TargetInitializer` and `ScorerInitializer` and stores the results in memory."
]
},
{
Expand All @@ -138,9 +138,9 @@
"# E.g. you can put it in .env\n",
"\n",
"from pyrit.setup import initialize_pyrit_async\n",
"from pyrit.setup.initializers import SimpleInitializer\n",
"from pyrit.setup.initializers import ScorerInitializer, TargetInitializer\n",
"\n",
"await initialize_pyrit_async(memory_db_type=\"InMemory\", initializers=[SimpleInitializer()]) # type: ignore\n",
"await initialize_pyrit_async(memory_db_type=\"InMemory\", initializers=[TargetInitializer(), ScorerInitializer()]) # type: ignore\n",
"\n",
"# Now you can run most of our notebooks! Just remove any os.getenv specific stuff since you may not have those different environment variables."
]
Expand Down Expand Up @@ -505,23 +505,22 @@
")\n",
"from pyrit.prompt_target import OpenAIChatTarget\n",
"from pyrit.setup import initialize_pyrit_async\n",
"from pyrit.setup.initializers import SimpleInitializer\n",
"from pyrit.setup.initializers import ScorerInitializer, TargetInitializer\n",
"\n",
"# This is a way to include the SimpleInitializer class directly\n",
"await initialize_pyrit_async(memory_db_type=\"InMemory\", initializers=[SimpleInitializer()]) # type: ignore\n",
"# This is a way to include the initializer classes directly\n",
"await initialize_pyrit_async(memory_db_type=\"InMemory\", initializers=[TargetInitializer(), ScorerInitializer()]) # type: ignore\n",
"\n",
"# Alternative approach - you can pass the path to the initializer class.\n",
"# This is how you provide your own file not part of the repo that defines a PyRITInitializer class\n",
"# This is equivalent to loading the class directly as above\n",
"# Alternative approach - you can pass the path to a file that defines PyRITInitializer classes.\n",
"# This is how you provide your own file not part of the repo. Here we point at the built-in\n",
"# targets module, which defines TargetInitializer.\n",
"await initialize_pyrit_async(\n",
" memory_db_type=\"InMemory\", initialization_scripts=[f\"{PYRIT_PATH}/setup/initializers/simple.py\"]\n",
" memory_db_type=\"InMemory\", initialization_scripts=[f\"{PYRIT_PATH}/setup/initializers/targets.py\"]\n",
") # type: ignore\n",
"\n",
"# SimpleInitializer is a class that initializes sensible defaults for someone who only has OPENAI_CHAT_ENDPOINT, OPENAI_CHAT_MODEL, and OPENAI_CHAT_KEY configured\n",
"# It is meant to only require these two env vars to be configured\n",
"# It can easily be swapped for another PyRITInitializer, like AIRTInitializer which is better but requires more env configuration\n",
"# TargetInitializer registers sensible default targets for someone who only has OPENAI_CHAT_ENDPOINT, OPENAI_CHAT_MODEL, and OPENAI_CHAT_KEY configured\n",
"# It can easily be combined with other PyRITInitializers (like ScorerInitializer) for a fuller setup\n",
"# get_info_async() is a class method that shows how this initializer configures defaults and what global variables it sets\n",
"info = await SimpleInitializer.get_info_async() # type: ignore\n",
"info = await TargetInitializer.get_info_async() # type: ignore\n",
"for key, value in info.items():\n",
" print(f\"{key}: {value}\")\n",
"\n",
Expand Down
27 changes: 13 additions & 14 deletions doc/code/setup/1_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
# %% [markdown]
# ## Simple Example
#
# This section goes into each of the three steps mentioned earlier. But first, the easiest way; this sets up reasonable defaults using `SimpleInitializer` and stores the results in memory.
# This section goes into each of the three steps mentioned earlier. But first, the easiest way; this sets up reasonable defaults using `TargetInitializer` and `ScorerInitializer` and stores the results in memory.

# %%
# Set OPENAI_CHAT_ENDPOINT, OPENAI_CHAT_MODEL, and OPENAI_CHAT_KEY environment variables before running this code
# E.g. you can put it in .env

from pyrit.setup import initialize_pyrit_async
from pyrit.setup.initializers import SimpleInitializer
from pyrit.setup.initializers import ScorerInitializer, TargetInitializer

await initialize_pyrit_async(memory_db_type="InMemory", initializers=[SimpleInitializer()]) # type: ignore
await initialize_pyrit_async(memory_db_type="InMemory", initializers=[TargetInitializer(), ScorerInitializer()]) # type: ignore

# Now you can run most of our notebooks! Just remove any os.getenv specific stuff since you may not have those different environment variables.

Expand Down Expand Up @@ -145,23 +145,22 @@
)
from pyrit.prompt_target import OpenAIChatTarget
from pyrit.setup import initialize_pyrit_async
from pyrit.setup.initializers import SimpleInitializer
from pyrit.setup.initializers import ScorerInitializer, TargetInitializer

# This is a way to include the SimpleInitializer class directly
await initialize_pyrit_async(memory_db_type="InMemory", initializers=[SimpleInitializer()]) # type: ignore
# This is a way to include the initializer classes directly
await initialize_pyrit_async(memory_db_type="InMemory", initializers=[TargetInitializer(), ScorerInitializer()]) # type: ignore

# Alternative approach - you can pass the path to the initializer class.
# This is how you provide your own file not part of the repo that defines a PyRITInitializer class
# This is equivalent to loading the class directly as above
# Alternative approach - you can pass the path to a file that defines PyRITInitializer classes.
# This is how you provide your own file not part of the repo. Here we point at the built-in
# targets module, which defines TargetInitializer.
await initialize_pyrit_async(
memory_db_type="InMemory", initialization_scripts=[f"{PYRIT_PATH}/setup/initializers/simple.py"]
memory_db_type="InMemory", initialization_scripts=[f"{PYRIT_PATH}/setup/initializers/targets.py"]
) # type: ignore

# SimpleInitializer is a class that initializes sensible defaults for someone who only has OPENAI_CHAT_ENDPOINT, OPENAI_CHAT_MODEL, and OPENAI_CHAT_KEY configured
# It is meant to only require these two env vars to be configured
# It can easily be swapped for another PyRITInitializer, like AIRTInitializer which is better but requires more env configuration
# TargetInitializer registers sensible default targets for someone who only has OPENAI_CHAT_ENDPOINT, OPENAI_CHAT_MODEL, and OPENAI_CHAT_KEY configured
# It can easily be combined with other PyRITInitializers (like ScorerInitializer) for a fuller setup
# get_info_async() is a class method that shows how this initializer configures defaults and what global variables it sets
info = await SimpleInitializer.get_info_async() # type: ignore
info = await TargetInitializer.get_info_async() # type: ignore
for key, value in info.items():
print(f"{key}: {value}")

Expand Down
Loading
Loading