DeepTeam is a framework to red team LLMs and AI agents.
.
A-Vamshi0f35e1bb2adb
diff --git a/deepteam/confident/api.py b/deepteam/confident/api.pyindex 18709d92..42f37d12 100644--- a/deepteam/confident/api.py+++ b/deepteam/confident/api.py@@ -24,6 +24,7 @@ from deepeval.confident.api import (class Endpoints(Enum):RISK_ASSESSMENT_ENDPOINT = "/v1/risk-assessments"+ RT_FRAMEWORK_ENDPOINT = "/v1/risk-assessments/frameworks/:frameworkId"class Api:diff --git a/deepteam/red_team.py b/deepteam/red_team.pyindex 81e7383e..a901d8bc 100644--- a/deepteam/red_team.py+++ b/deepteam/red_team.py@@ -6,14 +6,14 @@ from deepteam.attacks import BaseAttackfrom deepteam.attacks.multi_turn.types import CallbackTypefrom deepteam.red_teamer import RedTeamerfrom deepteam.attacks.attack_engine import AttackEngine-from deepteam.frameworks.frameworks import AISafetyFramework+from deepteam.frameworks.frameworks import RedTeamingFrameworkdef red_team(model_callback: CallbackType,vulnerabilities: Optional[List[BaseVulnerability]] = None,attacks: Optional[List[BaseAttack]] = None,- framework: Optional[AISafetyFramework] = None,+ framework: Optional[RedTeamingFramework] = None,simulator_model: DeepEvalBaseLLM = "gpt-4o-mini",evaluation_model: DeepEvalBaseLLM = "gpt-4o-mini",attacks_per_vulnerability_type: int = 1,diff --git a/deepteam/red_teamer/api.py b/deepteam/red_teamer/api.pyindex 413c8f43..0f16b703 100644--- a/deepteam/red_teamer/api.py+++ b/deepteam/red_teamer/api.py@@ -61,6 +61,7 @@ class APIRiskAssessment(BaseModel):run_duration: float = Field(alias="runDuration")identifier: Optional[str] = Field(alias="identifier")assessment_cost: Optional[float] = Field(alias="assessmentCost")+ rt_framework_id: Optional[str] = Field(None, alias="rtFrameworkId")test_cases: List[APIRTTestCase] = Field(alias="testCases")@@ -140,6 +141,7 @@ def map_risk_assessment_to_api(risk_assessment: RiskAssessment,assessment_cost: Optional[float] = None,identifier: Optional[str] = None,+ rt_framework_id: Optional[str] = None,) -> APIRiskAssessment:"""Map RiskAssessment to APIRiskAssessment.@@ -148,6 +150,8 @@ def map_risk_assessment_to_api(risk_assessment: The internal RiskAssessment objectidentifier: Optional[str] = None,assessment_cost: Optional[float] = None,+ rt_framework_id: id of the Confident AI framework this assessment ran,+ set only when the framework was pulled from Confident AI.Returns:APIRiskAssessment: The API-compatible risk assessment object@@ -173,5 +177,6 @@ def map_risk_assessment_to_api(runDuration=risk_assessment.overview.run_duration,identifier=identifier,assessmentCost=assessment_cost,+ rtFrameworkId=rt_framework_id,testCases=test_cases,)diff --git a/deepteam/red_teamer/red_teamer.py b/deepteam/red_teamer/red_teamer.pyindex ca6ed2d3..4b439c34 100644--- a/deepteam/red_teamer/red_teamer.py+++ b/deepteam/red_teamer/red_teamer.py@@ -18,7 +18,7 @@ from deepteam.red_teamer.api import map_risk_assessment_to_apifrom deepteam.test_case import RTTestCase, RTTurnfrom deepeval.utils import get_or_create_event_loop-from deepteam.frameworks.frameworks import AISafetyFramework+from deepteam.frameworks.frameworks import RedTeamingFrameworkfrom deepteam.frameworks.risk_category import RiskCategoryfrom deepteam.telemetry import capture_red_teamer_runfrom deepteam.attacks import BaseAttack@@ -97,7 +97,7 @@ class RedTeamer:attacks: Optional[List[BaseAttack]] = None,simulator_model: DeepEvalBaseLLM = None,evaluation_model: DeepEvalBaseLLM = None,- framework: Optional[AISafetyFramework] = None,+ framework: Optional[RedTeamingFramework] = None,attacks_per_vulnerability_type: int = 1,ignore_errors: bool = True,reuse_simulated_test_cases: bool = False,@@ -165,7 +165,7 @@ class RedTeamer:)if _upload_to_confident:self.risk_assessment = risk_assessment- self._post_risk_assessment()+ self._post_risk_assessment(rt_framework_id=framework._id)return risk_assessmentif framework and framework._has_dataset:@@ -302,7 +302,9 @@ class RedTeamer:if _print_assessment:self._print_risk_assessment(self.risk_assessment)if _upload_to_confident:- self._post_risk_assessment()+ self._post_risk_assessment(+ rt_framework_id=framework._id if framework else None+ )return self.risk_assessment@@ -313,7 +315,7 @@ class RedTeamer:attacks: Optional[List[BaseAttack]] = None,simulator_model: DeepEvalBaseLLM = None,evaluation_model: DeepEvalBaseLLM = None,- framework: Optional[AISafetyFramework] = None,+ framework: Optional[RedTeamingFramework] = None,attacks_per_vulnerability_type: int = 1,ignore_errors: bool = False,reuse_simulated_test_cases: bool = False,@@ -359,7 +361,7 @@ class RedTeamer:)if _upload_to_confident:self.risk_assessment = risk_assessment- self._post_risk_assessment()+ self._post_risk_assessment(rt_framework_id=framework._id)return risk_assessmentif framework:@@ -507,7 +509,9 @@ class RedTeamer:if _print_assessment:self._print_risk_assessment(self.risk_assessment)if _upload_to_confident:- self._post_risk_assessment()+ self._post_risk_assessment(+ rt_framework_id=framework._id if framework else None+ )return self.risk_assessment@@ -863,7 +867,7 @@ class RedTeamer:console.print("[bold magenta]LLM red teaming complete.[/bold magenta]")console.print("=" * 80 + "\n")- def _post_risk_assessment(self):+ def _post_risk_assessment(self, rt_framework_id: Optional[str] = None):if not is_confident():passing = 0failing = 0@@ -887,7 +891,9 @@ class RedTeamer:returnapi = Api()- api_risk_assessment = map_risk_assessment_to_api(self.risk_assessment)+ api_risk_assessment = map_risk_assessment_to_api(+ self.risk_assessment, rt_framework_id=rt_framework_id+ )try:body = api_risk_assessment.model_dump(by_alias=True, exclude_none=True@@ -1026,7 +1032,7 @@ class RedTeamer:model_callback: CallbackType,simulator_model: DeepEvalBaseLLM = None,evaluation_model: DeepEvalBaseLLM = None,- framework: Optional[AISafetyFramework] = None,+ framework: Optional[RedTeamingFramework] = None,attacks_per_vulnerability_type: int = 1,ignore_errors: bool = False,reuse_simulated_test_cases: bool = False,@@ -1069,6 +1075,10 @@ class RedTeamer:total=1,)framework_assessment = assess_risk_category(risk_category)+ # The framework's own risk category is more specific than+ # the one `red_team` derives from each vulnerability type.+ for test_case in framework_assessment.test_cases:+ test_case.risk_category = risk_category.nameresults[risk_category.name] = framework_assessmentupdate_pbar(progress_2, risk_task_id, advance_to_end=True)update_pbar(progress, task_id)@@ -1095,7 +1105,7 @@ class RedTeamer:model_callback: CallbackType,simulator_model: DeepEvalBaseLLM = None,evaluation_model: DeepEvalBaseLLM = None,- framework: Optional[AISafetyFramework] = None,+ framework: Optional[RedTeamingFramework] = None,attacks_per_vulnerability_type: int = 1,ignore_errors: bool = False,reuse_simulated_test_cases: bool = False,@@ -1130,6 +1140,10 @@ class RedTeamer:_print_assessment=False,_upload_to_confident=False,)+ # The framework's own risk category is more specific than+ # the one `a_red_team` derives from each vulnerability type.+ for test_case in assessment.test_cases:+ test_case.risk_category = category.nameupdate_pbar(progress_2, risk_task_id, advance_to_end=True)return category.name, assessmentdiff --git a/docs/content/docs/red-teaming-introduction.mdx b/docs/content/docs/red-teaming-introduction.mdxindex 5212b824..d9951ba1 100644--- a/docs/content/docs/red-teaming-introduction.mdx+++ b/docs/content/docs/red-teaming-introduction.mdx@@ -440,7 +440,7 @@ There is **ONE** mandatory and **ELEVEN** optional arguments when calling the `r- `model_callback`: a callback of type `Callable[[str], str]` that wraps around the target LLM system you wish to red team.- [Optional] `vulnerabilities`: a list of type `BaseVulnerability`s that determines the weaknesses to detect for.- [Optional] `attacks`: a list of type `BaseAttack`s that determines the methods that will be simulated to expose the defined `vulnerabilities`.-- [Optional] `framework`: an object of type `AISafetyFramework` that contains both `vulnerabilities` and `attacks` in it.+- [Optional] `framework`: an object of type `RedTeamingFramework` that contains both `vulnerabilities` and `attacks` in it.- [Optional] `simulator_model`: a string specifying which of OpenAI's GPT models to use, **OR** [any custom LLM model](https://docs.confident-ai.com/guides/guides-using-custom-llms) of type `DeepEvalBaseLLM` for simulating attacks. Defaulted to `"gpt-3.5-turbo-0125"`.- [Optional] `evaluation_model`: a string specifying which of OpenAI's GPT models to use, **OR** [any custom LLM model](https://docs.confident-ai.com/guides/guides-using-custom-llms) of type `DeepEvalBaseLLM` for evaluation. Defaulted to `"gpt-4o"`.- [Optional] `attacks_per_vulnerability_type`: an int that determines the number of attacks to be simulated per vulnerability type. Defaulted to `1`.@@ -593,7 +593,7 @@ As explained in the adversarial attack section, by making the PromptInjection atThere is **ONE** mandatory and **TEN** optional arguments when calling the `red_team()` method:- `model_callback`: a callback of type `Callable[[str], str]` that wraps around the target LLM system you wish to red team.-- [Optional] `framework`: an object of type `AISafetyFramework` that contains both `vulnerabilities` and `attacks` in it.+- [Optional] `framework`: an object of type `RedTeamingFramework` that contains both `vulnerabilities` and `attacks` in it.- [Optional] `simulator_model`: a string specifying which of OpenAI's GPT models to use, **OR** [any custom LLM model](https://docs.confident-ai.com/guides/guides-using-custom-llms) of type `DeepEvalBaseLLM` for simulating attacks. Defaulted to `"gpt-3.5-turbo-0125"`.- [Optional] `evaluation_model`: a string specifying which of OpenAI's GPT models to use, **OR** [any custom LLM model](https://docs.confident-ai.com/guides/guides-using-custom-llms) of type `DeepEvalBaseLLM` for evaluation. Defaulted to `"gpt-4o"`.- [Optional] `attacks_per_vulnerability_type`: an int that determines the number of attacks to be simulated per vulnerability type. Defaulted to `1`.