Skip to content

Commit 6bc07b4

Browse files
Minor fixes.
1 parent a153ddf commit 6bc07b4

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

articles/ai-foundry/how-to/develop/run-scans-ai-red-teaming-agent.md

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def simple_callback(query: str) -> str:
7272
red_team_result = await red_team_agent.scan(target=simple_callback)
7373
```
7474

75-
This example generates a default set of 10 attack prompts for each of the default set of four risk categories: violence, sexual, hate and unfairness, and self-harm. The example has a total of 40 rows of attack prompts to be generated and sent to your target.
75+
This example generates a default set of 10 attack prompts for each of the default set of four risk categories: violence, sexual, hate and unfairness, and self-harm. The example has a total of 40 rows of attack prompts to generat and send to your target.
7676

7777
Optionally, you can specify which risk categories of content risks you want to cover with `risk_categories` parameter and define the number of prompts covering each risk category with `num_objectives` parameter.
7878

@@ -96,7 +96,7 @@ red_team_agent = RedTeam(
9696
9797
## Region support
9898

99-
Currently, AI Red Teaming Agent is only available in a few regions. Ensure your Azure AI Project is located in the following supported regions:
99+
Currently, AI Red Teaming Agent is available only in some regions. Ensure your Azure AI Project is located in the following supported regions:
100100

101101
- East US2
102102
- Sweden Central
@@ -107,70 +107,70 @@ Currently, AI Red Teaming Agent is only available in a few regions. Ensure your
107107

108108
The `RedTeam` can run automated scans on various targets.
109109

110-
**Model configurations**: If you're just scanning a base model during your model selection process, you can pass in your model configuration as a target to your `red_team_agent.scan()`:
110+
- **Model configurations**: If you're just scanning a base model during your model selection process, you can pass in your model configuration as a target to your `red_team_agent.scan()`:
111111

112-
```python
113-
# Configuration for Azure OpenAI model
114-
azure_openai_config = {
115-
"azure_endpoint": os.environ.get("AZURE_OPENAI_ENDPOINT"),
116-
"api_key": os.environ.get("AZURE_OPENAI_KEY"), # not needed for entra ID based auth, use az login before running,
117-
"azure_deployment": os.environ.get("AZURE_OPENAI_DEPLOYMENT"),
118-
}
112+
```python
113+
# Configuration for Azure OpenAI model
114+
azure_openai_config = {
115+
"azure_endpoint": os.environ.get("AZURE_OPENAI_ENDPOINT"),
116+
"api_key": os.environ.get("AZURE_OPENAI_KEY"), # not needed for entra ID based auth, use az login before running,
117+
"azure_deployment": os.environ.get("AZURE_OPENAI_DEPLOYMENT"),
118+
}
119119

120-
red_team_result = await red_team_agent.scan(target=azure_openai_config)
121-
```
120+
red_team_result = await red_team_agent.scan(target=azure_openai_config)
121+
```
122122

123-
**Simple callback**: A simple callback that takes in a string prompt from `red_team_agent` and returns some string response from your application:
123+
- **Simple callback**: A simple callback that takes in a string prompt from `red_team_agent` and returns some string response from your application:
124124

125-
```python
126-
# Define a simple callback function that simulates a chatbot
127-
def simple_callback(query: str) -> str:
128-
# Your implementation to call your application (e.g., RAG system, chatbot)
129-
return "I'm an AI assistant that follows ethical guidelines. I cannot provide harmful content."
125+
```python
126+
# Define a simple callback function that simulates a chatbot
127+
def simple_callback(query: str) -> str:
128+
# Your implementation to call your application (e.g., RAG system, chatbot)
129+
return "I'm an AI assistant that follows ethical guidelines. I cannot provide harmful content."
130130

131-
red_team_result = await red_team_agent.scan(target=simple_callback)
132-
```
131+
red_team_result = await red_team_agent.scan(target=simple_callback)
132+
```
133133

134-
**Complex callback**: A more complex callback that is aligned to the OpenAI Chat Protocol:
134+
- **Complex callback**: A more complex callback that is aligned to the OpenAI Chat Protocol:
135135

136-
```python
137-
# Create a more complex callback function that handles conversation state
138-
async def advanced_callback(messages, stream=False, session_state=None, context=None):
139-
# Extract the latest message from the conversation history
140-
messages_list = [{"role": message.role, "content": message.content}
141-
for message in messages]
142-
latest_message = messages_list[-1]["content"]
136+
```python
137+
# Create a more complex callback function that handles conversation state
138+
async def advanced_callback(messages, stream=False, session_state=None, context=None):
139+
# Extract the latest message from the conversation history
140+
messages_list = [{"role": message.role, "content": message.content}
141+
for message in messages]
142+
latest_message = messages_list[-1]["content"]
143143

144-
# In a real application, you might process the entire conversation history
145-
# Here, we're just simulating a response
146-
response = "I'm an AI assistant that follows safety guidelines. I cannot provide harmful content."
144+
# In a real application, you might process the entire conversation history
145+
# Here, we're just simulating a response
146+
response = "I'm an AI assistant that follows safety guidelines. I cannot provide harmful content."
147147

148-
# Format the response to follow the expected chat protocol format
149-
formatted_response = {
150-
"content": response,
151-
"role": "assistant"
152-
}
148+
# Format the response to follow the expected chat protocol format
149+
formatted_response = {
150+
"content": response,
151+
"role": "assistant"
152+
}
153153

154-
return {"messages": [formatted_response]}
154+
return {"messages": [formatted_response]}
155155

156-
red_team_result = await red_team_agent.scan(target=advanced_callback)
157-
```
156+
red_team_result = await red_team_agent.scan(target=advanced_callback)
157+
```
158158

159-
**PyRIT prompt target**: For advanced users coming from PyRIT, `RedTeam` can also scan text-based PyRIT `PromptChatTarget`. See the full list of [PyRIT prompt targets](https://azure.github.io/PyRIT/code/targets/0_prompt_targets.html).
159+
- **PyRIT prompt target**: For advanced users coming from PyRIT, `RedTeam` can also scan text-based PyRIT `PromptChatTarget`. See the full list of [PyRIT prompt targets](https://azure.github.io/PyRIT/code/targets/0_prompt_targets.html).
160160

161-
```python
162-
from pyrit.prompt_target import OpenAIChatTarget, PromptChatTarget
161+
```python
162+
from pyrit.prompt_target import OpenAIChatTarget, PromptChatTarget
163163

164-
# Create a PyRIT PromptChatTarget for an Azure OpenAI model
165-
# This could be any class that inherits from PromptChatTarget
166-
chat_target = OpenAIChatTarget(
167-
model_name=os.environ.get("AZURE_OPENAI_DEPLOYMENT"),
168-
endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
169-
api_key=os.environ.get("AZURE_OPENAI_KEY")
170-
)
164+
# Create a PyRIT PromptChatTarget for an Azure OpenAI model
165+
# This could be any class that inherits from PromptChatTarget
166+
chat_target = OpenAIChatTarget(
167+
model_name=os.environ.get("AZURE_OPENAI_DEPLOYMENT"),
168+
endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
169+
api_key=os.environ.get("AZURE_OPENAI_KEY")
170+
)
171171

172-
red_team_result = await red_team_agent.scan(target=chat_target)
173-
```
172+
red_team_result = await red_team_agent.scan(target=chat_target)
173+
```
174174

175175
## Supported risk categories
176176

0 commit comments

Comments
 (0)