|
32 | 32 | "\n", |
33 | 33 | "These Scenarios can be updated and added to as you refine what you are testing for.\n", |
34 | 34 | "\n", |
| 35 | + "## How to Run Scenarios\n", |
| 36 | + "\n", |
| 37 | + "Scenarios should take almost no effort to run with default values. [pyrit_scan](../front_end/1_pyrit_scan.ipynb) and [pyrit_shell](../front_end/2_pyrit_shell.md) both use scenarios to execute.\n", |
| 38 | + "\n", |
35 | 39 | "## How It Works\n", |
36 | 40 | "\n", |
37 | 41 | "Each `Scenario` contains a collection of `AtomicAttack` objects. When executed:\n", |
|
80 | 84 | "execution_count": null, |
81 | 85 | "id": "1", |
82 | 86 | "metadata": {}, |
83 | | - "outputs": [], |
| 87 | + "outputs": [ |
| 88 | + { |
| 89 | + "name": "stdout", |
| 90 | + "output_type": "stream", |
| 91 | + "text": [ |
| 92 | + "Found default environment files: ['C:\\\\Users\\\\rlundeen\\\\.pyrit\\\\.env', 'C:\\\\Users\\\\rlundeen\\\\.pyrit\\\\.env.local']\n", |
| 93 | + "Loaded environment file: C:\\Users\\rlundeen\\.pyrit\\.env\n", |
| 94 | + "Loaded environment file: C:\\Users\\rlundeen\\.pyrit\\.env.local\n" |
| 95 | + ] |
| 96 | + } |
| 97 | + ], |
84 | 98 | "source": [ |
85 | 99 | "from typing import List, Optional, Type\n", |
86 | 100 | "\n", |
87 | 101 | "from pyrit.common import apply_defaults\n", |
88 | 102 | "from pyrit.executor.attack import AttackScoringConfig, PromptSendingAttack\n", |
89 | | - "from pyrit.models import SeedGroup, SeedObjective\n", |
90 | | - "from pyrit.scenario import AtomicAttack, Scenario, ScenarioStrategy\n", |
| 103 | + "from pyrit.scenario import (\n", |
| 104 | + " AtomicAttack,\n", |
| 105 | + " DatasetConfiguration,\n", |
| 106 | + " Scenario,\n", |
| 107 | + " ScenarioStrategy,\n", |
| 108 | + ")\n", |
91 | 109 | "from pyrit.scenario.core.scenario_strategy import ScenarioCompositeStrategy\n", |
92 | 110 | "from pyrit.score.true_false.true_false_scorer import TrueFalseScorer\n", |
| 111 | + "from pyrit.setup import initialize_pyrit_async\n", |
| 112 | + "\n", |
| 113 | + "await initialize_pyrit_async(memory_db_type=\"InMemory\") # type: ignore [top-level-await]\n", |
93 | 114 | "\n", |
94 | 115 | "\n", |
95 | 116 | "class MyStrategy(ScenarioStrategy):\n", |
|
101 | 122 | "class MyScenario(Scenario):\n", |
102 | 123 | " version: int = 1\n", |
103 | 124 | "\n", |
| 125 | + " # A strategy defintion helps callers define how to run your scenario (e.g. from the front_end)\n", |
104 | 126 | " @classmethod\n", |
105 | 127 | " def get_strategy_class(cls) -> Type[ScenarioStrategy]:\n", |
106 | 128 | " return MyStrategy\n", |
|
109 | 131 | " def get_default_strategy(cls) -> ScenarioStrategy:\n", |
110 | 132 | " return MyStrategy.ALL\n", |
111 | 133 | "\n", |
| 134 | + " # This is the default dataset configuration for this scenario (e.g. prompts to send)\n", |
| 135 | + " @classmethod\n", |
| 136 | + " def default_dataset_config(cls) -> DatasetConfiguration:\n", |
| 137 | + " return DatasetConfiguration(dataset_names=[\"dataset_name\"])\n", |
| 138 | + "\n", |
112 | 139 | " @apply_defaults\n", |
113 | 140 | " def __init__(\n", |
114 | 141 | " self,\n", |
|
146 | 173 | " )\n", |
147 | 174 | "\n", |
148 | 175 | " for strategy in selected_strategies:\n", |
149 | | - " # Create seed groups with objectives\n", |
150 | | - " seed_groups = [\n", |
151 | | - " SeedGroup(seeds=[SeedObjective(value=\"objective1\")]),\n", |
152 | | - " SeedGroup(seeds=[SeedObjective(value=\"objective2\")]),\n", |
153 | | - " ]\n", |
| 176 | + " # self._dataset_config is set by the parent class\n", |
| 177 | + " seed_groups = self._dataset_config.get_all_seed_groups()\n", |
154 | 178 | "\n", |
155 | 179 | " # Create attack instances based on strategy\n", |
156 | 180 | " attack = PromptSendingAttack(\n", |
|
165 | 189 | " memory_labels=self._memory_labels,\n", |
166 | 190 | " )\n", |
167 | 191 | " )\n", |
168 | | - " return atomic_attacks" |
| 192 | + " return atomic_attacks\n", |
| 193 | + " \n", |
| 194 | + "\n", |
| 195 | + "scenario = MyScenario()" |
169 | 196 | ] |
170 | 197 | }, |
171 | 198 | { |
|
205 | 232 | " Available Strategies (7):\n", |
206 | 233 | " hate, fairness, violence, sexual, harassment, misinformation, leakage\n", |
207 | 234 | " Default Strategy: all\n", |
208 | | - " Required Datasets (7):\n", |
| 235 | + " Default Datasets (7, max 4 per dataset):\n", |
209 | 236 | " airt_hate, airt_fairness, airt_violence, airt_sexual, airt_harassment,\n", |
210 | 237 | " airt_misinformation, airt_leakage\n", |
211 | 238 | "\u001b[1m\u001b[36m\n", |
|
221 | 248 | " Available Strategies (2):\n", |
222 | 249 | " single_turn, multi_turn\n", |
223 | 250 | " Default Strategy: all\n", |
224 | | - " Required Datasets (1):\n", |
| 251 | + " Default Datasets (1):\n", |
225 | 252 | " airt_malware\n", |
226 | 253 | "\u001b[1m\u001b[36m\n", |
227 | 254 | " foundry_scenario\u001b[0m\n", |
|
245 | 272 | " suffix_append, string_join, unicode_confusable, unicode_substitution,\n", |
246 | 273 | " url, jailbreak, tense, multi_turn, crescendo, pair, tap\n", |
247 | 274 | " Default Strategy: easy\n", |
248 | | - " Required Datasets (1):\n", |
| 275 | + " Default Datasets (1, max 4 per dataset):\n", |
249 | 276 | " harmbench\n", |
250 | 277 | "\u001b[1m\u001b[36m\n", |
251 | 278 | " garak.encoding_scenario\u001b[0m\n", |
|
268 | 295 | " uuencode, rot13, braille, atbash, morse_code, nato, ecoji, zalgo,\n", |
269 | 296 | " leet_speak, ascii_smuggler\n", |
270 | 297 | " Default Strategy: all\n", |
271 | | - " Required Datasets (2):\n", |
| 298 | + " Default Datasets (2, max 4 per dataset):\n", |
272 | 299 | " garak_slur_terms_en, garak_web_html_js\n", |
273 | 300 | "\n", |
274 | 301 | "================================================================================\n", |
|
0 commit comments