DeepTeam is a framework to red team LLMs and AI agents.
tests for model callback
A-Vamshi9ebd11e799f0
diff --git a/docs/docs/red-teaming-introduction.mdx b/docs/docs/red-teaming-introduction.mdxindex 32264600..3b808e8a 100644--- a/docs/docs/red-teaming-introduction.mdx+++ b/docs/docs/red-teaming-introduction.mdx@@ -49,7 +49,7 @@ from deepteam import red_teamfrom deepteam.vulnerabilities import Biasfrom deepteam.attacks.single_turn import PromptInjection-async def model_callback(input: str) -> str:+async def model_callback(input: str, turns=None) -> str:# Replace this with your LLM applicationreturn f"I'm sorry but I can't answer this: {input}"@@ -409,7 +409,7 @@ from deepteam import red_teamfrom deepteam.vulnerabilities import Biasfrom deepteam.attacks.single_turn import PromptInjection-async def model_callback(input: str) -> str:+async def model_callback(input: str, turns=None) -> str:# Replace this with your LLM applicationreturn f"I'm sorry but I can't answer this: {input}"@@ -488,7 +488,7 @@ from deepteam.vulnerabilities import Biasfrom deepteam.attacks.single_turn import PromptInjection, ROT13from deepteam.red_teamer import RedTeamer-async def model_callback(input: str) -> str:+async def model_callback(input: str, turns=None) -> str:# Replace this with your LLM applicationreturn f"I'm sorry but I can't answer this: {input}"diff --git a/tests/test_core/test_model_callback.py b/tests/test_core/test_model_callback.pynew file mode 100644index 00000000..e4d14d83--- /dev/null+++ b/tests/test_core/test_model_callback.py@@ -0,0 +1,55 @@+import pytest+import inspect+import asyncio+from deepteam.red_teamer.utils import resolve_model_callback+from deepeval.models import GPTModel+from deepteam.vulnerabilities import Bias+from deepteam.attacks.single_turn import Roleplay+from deepteam import red_team+++class TestModelCallbackVariations:++ def test_openai_valid_sync_model(self):+ OPENAI_MODEL = "openai/gpt-4.1"+ model_callback = resolve_model_callback(OPENAI_MODEL, False)+ assert not inspect.iscoroutinefunction(model_callback)+ assert model_callback("Hello") is not None++ def test_openai_valid_async_model(self):+ OPENAI_MODEL = "openai/gpt-4.1"+ model_callback = resolve_model_callback(OPENAI_MODEL, True)+ assert inspect.iscoroutinefunction(model_callback)+ assert asyncio.run(model_callback("Hello")) is not None++ def test_deepeval_base_llm_sync_model(self):+ model = GPTModel(model="gpt-3.5-turbo")+ model_callback = resolve_model_callback(model, False)+ assert not inspect.iscoroutinefunction(model_callback)+ assert model_callback("Hello") is not None++ def test_deepeval_base_llm_async_model(self):+ model = GPTModel(model="gpt-3.5-turbo")+ model_callback = resolve_model_callback(model, True)+ assert inspect.iscoroutinefunction(model_callback)+ assert asyncio.run(model_callback("Hello")) is not None++ def test_simple_red_teaming_async(self):+ OPENAI_MODEL = "openai/gpt-4.1"+ risk_assessment = red_team(+ model_callback=OPENAI_MODEL,+ attacks=[Roleplay()],+ vulnerabilities=[Bias(types=["gender"])],+ async_mode=True+ )+ assert risk_assessment is not None++ def test_simple_red_teaming_sync(self):+ OPENAI_MODEL = "openai/gpt-4.1"+ risk_assessment = red_team(+ model_callback=OPENAI_MODEL,+ attacks=[Roleplay()],+ vulnerabilities=[Bias(types=["gender"])],+ async_mode=False+ )+ assert risk_assessment is not None