Skip to content

DeepTeam is a framework to red team LLMs and AI agents.

.

A-Vamshi2da120bc1de9
diff --git a/deepteam/attacks/multi_turn/crescendo_jailbreaking/crescendo_jailbreaking.py b/deepteam/attacks/multi_turn/crescendo_jailbreaking/crescendo_jailbreaking.py
index f4e27e4f..abf89b72 100644
--- a/deepteam/attacks/multi_turn/crescendo_jailbreaking/crescendo_jailbreaking.py
+++ b/deepteam/attacks/multi_turn/crescendo_jailbreaking/crescendo_jailbreaking.py
@@ -212,7 +212,9 @@ class CrescendoJailbreaking(BaseMultiTurnAttack):
)
)
else:
- turns.append(RTTurn(role="assistant", content=last_response))
+ turns.append(
+ RTTurn(role="assistant", content=last_response)
+ )
is_refusal, refusal_rationale = self.get_refusal_score(
last_response, current_attack, vulnerability_data
@@ -383,7 +385,9 @@ class CrescendoJailbreaking(BaseMultiTurnAttack):
)
)
else:
- turns.append(RTTurn(role="assistant", content=last_response))
+ turns.append(
+ RTTurn(role="assistant", content=last_response)
+ )
is_refusal, refusal_rationale = await self.a_get_refusal_score(
last_response, current_attack, vulnerability_data
diff --git a/deepteam/red_teamer/red_teamer.py b/deepteam/red_teamer/red_teamer.py
index 4ff32316..0b97fdc9 100644
--- a/deepteam/red_teamer/red_teamer.py
+++ b/deepteam/red_teamer/red_teamer.py
@@ -93,9 +93,13 @@ class RedTeamer:
raise ValueError(
"You can only pass either 'framework' or 'attacks' and 'vulnerabilities' at the same time"
)
-
- if isinstance(model_callback, str) or isinstance(model_callback, DeepEvalBaseLLM):
- model_callback = resolve_model_callback(model_callback, self.async_mode)
+
+ if isinstance(model_callback, str) or isinstance(
+ model_callback, DeepEvalBaseLLM
+ ):
+ model_callback = resolve_model_callback(
+ model_callback, self.async_mode
+ )
if self.async_mode:
validate_model_callback_signature(
@@ -284,8 +288,12 @@ class RedTeamer:
_print_assessment: Optional[bool] = True,
_upload_to_confident: Optional[bool] = True,
):
- if isinstance(model_callback, str) or isinstance(model_callback, DeepEvalBaseLLM):
- model_callback = resolve_model_callback(model_callback, self.async_mode)
+ if isinstance(model_callback, str) or isinstance(
+ model_callback, DeepEvalBaseLLM
+ ):
+ model_callback = resolve_model_callback(
+ model_callback, self.async_mode
+ )
if not framework and not vulnerabilities:
raise ValueError(
diff --git a/deepteam/red_teamer/utils.py b/deepteam/red_teamer/utils.py
index f8c35928..7c2c52c6 100644
--- a/deepteam/red_teamer/utils.py
+++ b/deepteam/red_teamer/utils.py
@@ -4,13 +4,13 @@ from deepteam.test_case import RTTestCase, RTTurn
from deepteam.vulnerabilities.types import VulnerabilityType
from deepeval.models import (
DeepEvalBaseLLM,
- GPTModel,
+ GPTModel,
GeminiModel,
GrokModel,
KimiModel,
AnthropicModel,
DeepSeekModel,
- OllamaModel
+ OllamaModel,
)
from deepeval.metrics.utils import initialize_model
@@ -21,7 +21,7 @@ MODEL_PROVIDER_MAPPING = {
"xai": GrokModel,
"moonshotai": KimiModel,
"deepseek": DeepSeekModel,
- "ollama": OllamaModel
+ "ollama": OllamaModel,
}
@@ -48,7 +48,9 @@ def group_attacks_by_vulnerability_type(
return vulnerability_type_to_attacks_map
-def resolve_model_callback(model_callback: Union[str, DeepEvalBaseLLM], async_mode: bool):
+def resolve_model_callback(
+ model_callback: Union[str, DeepEvalBaseLLM], async_mode: bool
+):
if isinstance(model_callback, str):
if "/" in model_callback:
provider, model = model_callback.split("/", 1)
@@ -63,16 +65,23 @@ def resolve_model_callback(model_callback: Union[str, DeepEvalBaseLLM], async_mo
raise ValueError(
f"Invalid string for model_callback {model_callback}, please pass a string with provider prefix separated by a '/'. Ex: 'openai/gpt-4.1'. Avaliable provider prefixes: {[key for key in MODEL_PROVIDER_MAPPING.keys()]}"
)
-
+
model_callback, _ = initialize_model(model_callback)
-
+
if not async_mode:
- def new_model_callback(input: str, turns: Optional[List[RTTurn]] = None):
+
+ def new_model_callback(
+ input: str, turns: Optional[List[RTTurn]] = None
+ ):
res, _ = model_callback.generate(input)
return res
+
else:
- async def new_model_callback(input: str, turns: Optional[List[RTTurn]] = None):
+
+ async def new_model_callback(
+ input: str, turns: Optional[List[RTTurn]] = None
+ ):
res, _ = await model_callback.a_generate(input)
return res
-
+
return new_model_callback