DeepTeam is a framework to red team LLMs and AI agents.
.
A-Vamshifed3ab5d29b7
diff --git a/deepteam/red_teamer/utils.py b/deepteam/red_teamer/utils.pyindex 5b08b4b9..5aa32033 100644--- a/deepteam/red_teamer/utils.py+++ b/deepteam/red_teamer/utils.py@@ -1,5 +1,5 @@from typing import List, Dict, Union, Optional-+from functools import wrapsfrom deepteam.test_case import RTTestCase, RTTurnfrom deepteam.vulnerabilities.types import VulnerabilityTypefrom deepeval.models import (@@ -48,6 +48,41 @@ def group_attacks_by_vulnerability_type(return vulnerability_type_to_attacks_map+def wrap_model_callback(model_callback, async_mode):++ def _validate_response(response):+ """Helper to strictly validate the callback's return value."""+ if isinstance(response, RTTurn):+ if response.role == "assistant":+ return response+ else:+ raise ValueError(+ "The target model must return an 'RTTurn' with role='assistant' only."+ )+ elif isinstance(response, str):+ return RTTurn(+ role="assistant",+ content=response+ )+ else:+ raise TypeError(+ f"The target model callback has returned an invalid response of type {type(response)}. "+ "Please return either a string or an 'RTTurn' with role='assistant'."+ )++ @wraps(model_callback)+ def get_sync_model_callback(input: str, turns: List[RTTurn] = None):+ response = model_callback(input, turns)+ return _validate_response(response)++ @wraps(model_callback)+ async def get_async_model_callback(input: str, turns: List[RTTurn] = None):+ response = await model_callback(input, turns)+ return _validate_response(response)++ return get_async_model_callback if async_mode else get_sync_model_callback++def resolve_model_callback(model_callback: Union[str, DeepEvalBaseLLM], async_mode: bool):