(target_url: str, questions_per_category: int = 1, scan_name: Optional[str] = None)
| 48 | |
| 49 | |
| 50 | async def run_redteaming(target_url: str, questions_per_category: int = 1, scan_name: Optional[str] = None): |
| 51 | AZURE_AI_FOUNDRY = os.getenv("AZURE_AI_FOUNDRY") |
| 52 | AZURE_AI_PROJECT = os.getenv("AZURE_AI_PROJECT") |
| 53 | model_red_team = RedTeam( |
| 54 | azure_ai_project=f"https://{AZURE_AI_FOUNDRY}.services.ai.azure.com/api/projects/{AZURE_AI_PROJECT}", |
| 55 | credential=get_azure_credential(), |
| 56 | risk_categories=[ |
| 57 | RiskCategory.Violence, |
| 58 | RiskCategory.HateUnfairness, |
| 59 | RiskCategory.Sexual, |
| 60 | RiskCategory.SelfHarm, |
| 61 | ], |
| 62 | num_objectives=questions_per_category, |
| 63 | ) |
| 64 | |
| 65 | if scan_name is None: |
| 66 | timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") |
| 67 | scan_name = f"Safety evaluation {timestamp}" |
| 68 | |
| 69 | await model_red_team.scan( |
| 70 | scan_name=scan_name, |
| 71 | output_path=f"{root_dir}/redteams/{scan_name}.json", |
| 72 | attack_strategies=[ |
| 73 | AttackStrategy.Baseline, |
| 74 | # Easy Complexity: |
| 75 | AttackStrategy.Morse, |
| 76 | AttackStrategy.UnicodeConfusable, |
| 77 | AttackStrategy.Url, |
| 78 | # Moderate Complexity: |
| 79 | AttackStrategy.Tense, |
| 80 | # Difficult Complexity: |
| 81 | AttackStrategy.Compose([AttackStrategy.Tense, AttackStrategy.Url]), |
| 82 | ], |
| 83 | target=lambda query: callback(query, target_url), |
| 84 | ) |
| 85 | |
| 86 | |
| 87 | if __name__ == "__main__": |
no test coverage detected