|
126 | 126 | "azure_openai_api_version = \"2023-12-01-preview\" # Use the latest API version" |
127 | 127 | ] |
128 | 128 | }, |
129 | | - { |
130 | | - "cell_type": "code", |
131 | | - "execution_count": null, |
132 | | - "metadata": {}, |
133 | | - "outputs": [], |
134 | | - "source": [ |
135 | | - "# Azure AI Project information\n", |
136 | | - "azure_ai_project = {\n", |
137 | | - " \"subscription_id\": os.environ.get(\"AZURE_SUBSCRIPTION_ID\"),\n", |
138 | | - " \"resource_group_name\": os.environ.get(\"AZURE_RESOURCE_GROUP_NAME\"),\n", |
139 | | - " \"project_name\": os.environ.get(\"AZURE_PROJECT_NAME\"),\n", |
140 | | - "}\n", |
141 | | - "\n", |
142 | | - "# Azure OpenAI deployment information\n", |
143 | | - "azure_openai_deployment = os.environ.get(\"AZURE_OPENAI_DEPLOYMENT\") # e.g., \"gpt-4\"\n", |
144 | | - "azure_openai_endpoint = os.environ.get(\n", |
145 | | - " \"AZURE_OPENAI_ENDPOINT\"\n", |
146 | | - ") # e.g., \"https://endpoint-name.openai.azure.com/openai/deployments/deployment-name/chat/completions\"\n", |
147 | | - "azure_openai_api_key = os.environ.get(\"AZURE_OPENAI_API_KEY\") # e.g., \"your-api-key\"\n", |
148 | | - "azure_openai_api_version = \"2023-12-01-preview\" # Use the latest API version" |
149 | | - ] |
150 | | - }, |
151 | 129 | { |
152 | 130 | "cell_type": "markdown", |
153 | 131 | "metadata": {}, |
|
255 | 233 | "# Run the red team scan called \"Basic-Callback-Scan\" with limited scope for this basic example\n", |
256 | 234 | "# This will test 1 objective prompt for each of Violence and HateUnfairness categories with the Flip strategy\n", |
257 | 235 | "result = await red_team.scan(\n", |
258 | | - " target=financial_advisor_callback, scan_name=\"Basic-Callback-Scan\", attack_strategies=[AttackStrategy.Flip]\n", |
| 236 | + " target=financial_advisor_callback,\n", |
| 237 | + " scan_name=\"Basic-Callback-Scan\",\n", |
| 238 | + " attack_strategies=[AttackStrategy.Flip],\n", |
| 239 | + " output_file=\"red_team_output.json\",\n", |
259 | 240 | ")" |
260 | 241 | ] |
261 | 242 | }, |
|
422 | 403 | "The data and results used in this attack will be saved to the `output_path` specified. The URL printed out at the end of the scorecard will provide a link to where you results are uploaded and logged to your Azure AI Foundry project." |
423 | 404 | ] |
424 | 405 | }, |
| 406 | + { |
| 407 | + "cell_type": "markdown", |
| 408 | + "metadata": {}, |
| 409 | + "source": [ |
| 410 | + "## Bring your own objectives: Using your own prompts as objectives for RedTeam\n", |
| 411 | + "\n", |
| 412 | + "Below we demonstrate how to use your own prompts as objectives for a `RedTeam` scan. You can see the required format for prompts under `.\\data\\prompts.json`. Note that when bringing your own prompts, the supported `risk-type`s are `violence`, `sexual`, `hate_unfairness`, and `self_harm`. The number of prompts you specify will be the `num_objectives` used in the scan. " |
| 413 | + ] |
| 414 | + }, |
| 415 | + { |
| 416 | + "cell_type": "code", |
| 417 | + "execution_count": null, |
| 418 | + "metadata": {}, |
| 419 | + "outputs": [], |
| 420 | + "source": [ |
| 421 | + "path_to_prompts = \".\\data\\prompts.json\"\n", |
| 422 | + "\n", |
| 423 | + "# Create the RedTeam specifying the custom attack seed prompts to use as objectives\n", |
| 424 | + "custom_red_team = RedTeam(\n", |
| 425 | + " azure_ai_project=azure_ai_project,\n", |
| 426 | + " credential=credential,\n", |
| 427 | + " custom_attack_seed_prompts=path_to_prompts, # Path to a file containing custom attack seed prompts\n", |
| 428 | + ")" |
| 429 | + ] |
| 430 | + }, |
| 431 | + { |
| 432 | + "cell_type": "code", |
| 433 | + "execution_count": null, |
| 434 | + "metadata": {}, |
| 435 | + "outputs": [], |
| 436 | + "source": [ |
| 437 | + "custom_red_team_result = await custom_red_team.scan(\n", |
| 438 | + " target=azure_openai_callback,\n", |
| 439 | + " scan_name=\"Custom-Prompt-Scan\",\n", |
| 440 | + " attack_strategies=[\n", |
| 441 | + " AttackStrategy.EASY, # Group of easy complexity attacks\n", |
| 442 | + " AttackStrategy.MODERATE, # Group of moderate complexity attacks\n", |
| 443 | + " AttackStrategy.DIFFICULT, # Group of difficult complexity attacks\n", |
| 444 | + " ],\n", |
| 445 | + " output_path=\"Custom-Prompt-Scan.json\",\n", |
| 446 | + ")" |
| 447 | + ] |
| 448 | + }, |
425 | 449 | { |
426 | 450 | "cell_type": "markdown", |
427 | 451 | "metadata": {}, |
|
450 | 474 | ], |
451 | 475 | "metadata": { |
452 | 476 | "kernelspec": { |
453 | | - "display_name": ".venv", |
| 477 | + "display_name": "test-3.10", |
454 | 478 | "language": "python", |
455 | 479 | "name": "python3" |
456 | 480 | }, |
|
0 commit comments