|
14 | 14 | "\n", |
15 | 15 | "## Before you begin\n", |
16 | 16 | "\n", |
| 17 | + "### Prerequisite\n", |
| 18 | + "The AI Red Teaming Agent requires an Azure AI Foundry project configuration and Azure credentials. Your project configuration will be used to log red teaming scan results after the run is finished.\n", |
| 19 | + "\n", |
| 20 | + "**Important**: Make sure to authenticate to Azure using `az login` in your terminal before running this notebook.\n", |
| 21 | + "\n", |
17 | 22 | "### Installation\n", |
18 | | - "Execute the following cells in a terminal window. Install the following packages required to execute this notebook, then use the virtual environment created as kernel to run the remainder of this notebook." |
| 23 | + "From a terminal window, navigate to your working directory which contains this sample notebook, and execute the following.\n", |
| 24 | + "```bash\n", |
| 25 | + "python -m venv .venv\n", |
| 26 | + "```\n", |
| 27 | + "\n", |
| 28 | + "Then, activate the virtual environment created:\n", |
| 29 | + "\n", |
| 30 | + "```bash\n", |
| 31 | + "# %source .venv/bin/activate # If using Mac/Linux OS\n", |
| 32 | + ".venv/Scripts/activate # If using Windows OS\n", |
| 33 | + "```\n", |
| 34 | + "\n", |
| 35 | + "With your virtual environment activated, install the following packages required to execute this notebook:\n", |
| 36 | + "\n", |
| 37 | + "```bash\n", |
| 38 | + "pip install uv\n", |
| 39 | + "uv pip install azure-ai-evaluation[redteam] termcolor==2.5.0 azure-identity openai\n", |
| 40 | + "```\n", |
| 41 | + "\n", |
| 42 | + "\n", |
| 43 | + "Now open VSCode with the following command, and ensure your virtual environment is used as kernel to run the remainder of this notebook.\n", |
| 44 | + "```bash\n", |
| 45 | + "code .\n", |
| 46 | + "```" |
19 | 47 | ] |
20 | 48 | }, |
21 | 49 | { |
22 | | - "cell_type": "code", |
23 | | - "execution_count": null, |
| 50 | + "cell_type": "markdown", |
24 | 51 | "metadata": {}, |
25 | | - "outputs": [], |
26 | 52 | "source": [ |
27 | | - "%%python -m venv .venv\n", |
28 | | - "# %source .venv/bin/activate # If using Mac/Linux OS\n", |
29 | | - "%.venv/Scripts/activate # If using Windows OS\n", |
30 | | - "%pip install uv" |
| 53 | + "### Imports" |
31 | 54 | ] |
32 | 55 | }, |
33 | 56 | { |
|
36 | 59 | "metadata": {}, |
37 | 60 | "outputs": [], |
38 | 61 | "source": [ |
39 | | - "# install the packages\n", |
40 | | - "%uv pip install azure-ai-evaluation[redteam] termcolor==2.5.0 azure-identity openai" |
| 62 | + "from typing import Optional, Dict, Any\n", |
| 63 | + "import os\n", |
| 64 | + "\n", |
| 65 | + "# Azure imports\n", |
| 66 | + "from azure.identity import DefaultAzureCredential, get_bearer_token_provider\n", |
| 67 | + "from azure.ai.evaluation import RedTeam, RiskCategory, AttackStrategy\n", |
| 68 | + "\n", |
| 69 | + "# OpenAI imports\n", |
| 70 | + "from openai import AzureOpenAI\n", |
| 71 | + "\n", |
| 72 | + "# Initialize Azure credentials\n", |
| 73 | + "credential = DefaultAzureCredential()" |
41 | 74 | ] |
42 | 75 | }, |
43 | 76 | { |
|
77 | 110 | "metadata": {}, |
78 | 111 | "outputs": [], |
79 | 112 | "source": [ |
80 | | - "import os\n", |
81 | | - "\n", |
82 | 113 | "# Azure AI Project information\n", |
83 | 114 | "azure_ai_project = {\n", |
84 | 115 | " \"subscription_id\": os.environ.get(\"AZURE_SUBSCRIPTION_ID\"),\n", |
|
95 | 126 | "azure_openai_api_version = \"2023-12-01-preview\" # Use the latest API version" |
96 | 127 | ] |
97 | 128 | }, |
98 | | - { |
99 | | - "cell_type": "markdown", |
100 | | - "metadata": {}, |
101 | | - "source": [ |
102 | | - "### Configuration\n", |
103 | | - "The AI Red Teaming Agent requires an Azure AI Foundry project configuration and Azure credentials. Your project configuration will be used to log red teaming scan results after the run is finished.\n", |
104 | | - "\n", |
105 | | - "**Important**: Make sure to authenticate to Azure using `az login` in your terminal before running this notebook." |
106 | | - ] |
107 | | - }, |
108 | | - { |
109 | | - "cell_type": "code", |
110 | | - "execution_count": null, |
111 | | - "metadata": {}, |
112 | | - "outputs": [], |
113 | | - "source": [ |
114 | | - "from typing import Optional, Dict, Any\n", |
115 | | - "\n", |
116 | | - "# Azure imports\n", |
117 | | - "from azure.identity import DefaultAzureCredential, get_bearer_token_provider\n", |
118 | | - "from azure.ai.evaluation import RedTeam, RiskCategory, AttackStrategy\n", |
119 | | - "\n", |
120 | | - "# OpenAI imports\n", |
121 | | - "from openai import AzureOpenAI\n", |
122 | | - "\n", |
123 | | - "# Initialize Azure credentials\n", |
124 | | - "credential = DefaultAzureCredential()" |
125 | | - ] |
126 | | - }, |
127 | 129 | { |
128 | 130 | "cell_type": "markdown", |
129 | 131 | "metadata": {}, |
|
199 | 201 | "metadata": {}, |
200 | 202 | "outputs": [], |
201 | 203 | "source": [ |
202 | | - "# Create the RedTeam instance with minimal configurations\n", |
| 204 | + "# Create the `RedTeam` instance with minimal configurations\n", |
203 | 205 | "red_team = RedTeam(\n", |
204 | 206 | " azure_ai_project=azure_ai_project,\n", |
205 | 207 | " credential=credential,\n", |
|
219 | 221 | "cell_type": "markdown", |
220 | 222 | "metadata": {}, |
221 | 223 | "source": [ |
222 | | - "Now let's run a simple red team evaluation using the fixed response target. We'll test against two risk categories and one attack strategy for simplicity." |
| 224 | + "Now let's run a simple automated scan using the `RedTeam` with the fixed response target. We'll test against two risk categories and one attack strategy for simplicity." |
223 | 225 | ] |
224 | 226 | }, |
225 | 227 | { |
|
0 commit comments