From 07143a4cac4cf040c32bc88a95ae8bba8b6279f7 Mon Sep 17 00:00:00 2001 From: Nagendra Posani Date: Mon, 19 May 2025 17:54:12 -0700 Subject: [PATCH] added --- .../samples/evaluation/sample_redteam.ipynb | 88 ++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/samples/evaluation/sample_redteam.ipynb b/sdk/ai/azure-ai-projects/samples/evaluation/sample_redteam.ipynb index 1198b5a85282..41d98a93ebef 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluation/sample_redteam.ipynb +++ b/sdk/ai/azure-ai-projects/samples/evaluation/sample_redteam.ipynb @@ -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": {}, @@ -180,4 +266,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +}