Skip to content

Added callback scenarios #41207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: feature/CloudEvalSamples
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,92 @@
"print(f\"Red Team scan created with scan name: {red_team_response.name}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Callback Target Cloud Red Team Scan\n",
"\n",
"This section demonstrates the upcoming advanced callback scenarios in cloud red team scans."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Simple in-line callback\n",
"\n",
"This sample provides a simple in-line callback that allows customers to send inline function for the callback to be run in cloud during the red team scan."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create a Red Team scan\n",
"print(\"Creating a Red Team scan with inline callback\")\n",
"\n",
"# Create target configuration for red teaming\n",
"target_config = InLineCallbackConfiguration(callback={\n",
" \"type\": \"InLineCallback\",\n",
" \"function\": \"print('Red Team inline scan')\",\n",
"})\n",
"\n",
"# Create the Red Team configuration\n",
"red_team = RedTeam(\n",
" attack_strategies=[AttackStrategy.BASE64],\n",
" risk_categories=[RiskCategory.VIOLENCE],\n",
" display_name=\"redteamtest1\", # Use a simpler name\n",
" target=target_config,\n",
")\n",
"\n",
"# Create and run the Red Team scan\n",
"red_team_response = project_client.red_teams.create(red_team=red_team)\n",
"print(f\"Red Team scan created with scan name: {red_team_response.name}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Advanced callback\n",
"\n",
"This sample provides advanced callback that allows customers to send callback function from a python file, registered as an asset, to be run in cloud during the red team scan."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create a Red Team scan\n",
"print(\"Creating a Red Team scan for direct model testing\")\n",
"\n",
"callback = project_client.datasets.upload_file(\n",
" name=callback_name,\n",
" version=\"1\",\n",
" file=\"./samples_folder/callback.py\",\n",
")\n",
"\n",
"# Create target configuration for red teaming\n",
"target_config = AdvancedCallbackConfiguration(callback_id=callback.id)\n",
"\n",
"# Create the Red Team configuration\n",
"red_team = RedTeam(\n",
" attack_strategies=[AttackStrategy.BASE64],\n",
" risk_categories=[RiskCategory.VIOLENCE],\n",
" display_name=\"redteamtest1\", # Use a simpler name\n",
" target=target_config,\n",
")\n",
"\n",
"# Create and run the Red Team scan\n",
"red_team_response = project_client.red_teams.create(red_team=red_team)\n",
"print(f\"Red Team scan created with scan name: {red_team_response.name}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -180,4 +266,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
Loading