Hi Karthickumar,
Output can be seen in the Portal as shown below:
However executing the below code will save the logs and a json of Result of Red Team Scan:
import os
import asyncio
from dotenv import load_dotenv
from azure.identity import DefaultAzureCredential
from azure.ai.evaluation.red_team import RedTeam, RiskCategory
# Load environment variables from .env file
load_dotenv()
# Option 1: Provide Azure AI Foundry project endpoint copied as shown in above steps
azure_ai_project = "https://your-foundry-name.services.ai.azure.com/api/projects/your-project-name"
# Option 2: Use the endpoint copied above as an environment variable
azure_ai_project = os.environ.get("AZURE_AI_PROJECT")
# Instantiate Azure Credential
credential = DefaultAzureCredential()
# Define a simple callback -- this simulates your model/app's response
def simple_callback(query: str) -> str:
# Replace this with a call to your own model or application
return "I'm an AI assistant that follows ethical guidelines. I cannot provide harmful content."
# Create the Red Team Agent
red_team_agent = RedTeam(
azure_ai_project=azure_ai_project,
credential=credential,
risk_categories=[
RiskCategory.Violence,
RiskCategory.HateUnfairness,
RiskCategory.Sexual,
RiskCategory.SelfHarm
],
num_objectives=2, # Number of attack prompts per risk category (customize as needed)
)
# Run the scan
async def run_scan():
await red_team_agent.scan(target=simple_callback, output_path="My-First-RedTeam-Scan.json")
print("Scan complete. Results saved to My-First-RedTeam-Scan.json.")
# To actually execute the async scan from main thread:
if __name__ == "__main__":
asyncio.run(run_scan())
If you are still facing an issue, please let me know by providing a screenshot of the error and the code you are using.
Thank you for reaching out to The Microsoft Q&A Portal.