Skip to content

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

evaluation cost

A-Vamshi00b6617d0c2c
diff --git a/deepteam/metrics/agent_identity_abuse/agent_identity_abuse.py b/deepteam/metrics/agent_identity_abuse/agent_identity_abuse.py
index 2e21a1ae..a7401852 100644
--- a/deepteam/metrics/agent_identity_abuse/agent_identity_abuse.py
+++ b/deepteam/metrics/agent_identity_abuse/agent_identity_abuse.py
@@ -51,7 +51,7 @@ class AgentIdentityAbuseMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -77,7 +77,7 @@ class AgentIdentityAbuseMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -126,7 +126,8 @@ class AgentIdentityAbuseMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -166,7 +167,8 @@ class AgentIdentityAbuseMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/amnesia_assessment/amnesia_assessment.py b/deepteam/metrics/agentic/amnesia_assessment/amnesia_assessment.py
index 0d5eb48e..719615ca 100644
--- a/deepteam/metrics/agentic/amnesia_assessment/amnesia_assessment.py
+++ b/deepteam/metrics/agentic/amnesia_assessment/amnesia_assessment.py
@@ -50,7 +50,7 @@ class AmnesiaAssessmentMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class AmnesiaAssessmentMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class AmnesiaAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class AmnesiaAssessmentMetric(BaseRedTeamingMetric):
prompt = AmnesiaAssessmentTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class AmnesiaAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class AmnesiaAssessmentMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/boundary_violation/boundary_violation.py b/deepteam/metrics/agentic/boundary_violation/boundary_violation.py
index 1ac17129..e107bb4b 100644
--- a/deepteam/metrics/agentic/boundary_violation/boundary_violation.py
+++ b/deepteam/metrics/agentic/boundary_violation/boundary_violation.py
@@ -50,7 +50,7 @@ class BoundaryViolationMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class BoundaryViolationMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class BoundaryViolationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class BoundaryViolationMetric(BaseRedTeamingMetric):
prompt = BoundaryViolationTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class BoundaryViolationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class BoundaryViolationMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/domain_validation/domain_validation.py b/deepteam/metrics/agentic/domain_validation/domain_validation.py
index 5bb7c6e4..22fa0d64 100644
--- a/deepteam/metrics/agentic/domain_validation/domain_validation.py
+++ b/deepteam/metrics/agentic/domain_validation/domain_validation.py
@@ -50,7 +50,7 @@ class DomainValidationMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class DomainValidationMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class DomainValidationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class DomainValidationMetric(BaseRedTeamingMetric):
prompt = DomainValidationTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class DomainValidationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class DomainValidationMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/escalation_success/escalation_success.py b/deepteam/metrics/agentic/escalation_success/escalation_success.py
index 4ca18a5f..fe007af8 100644
--- a/deepteam/metrics/agentic/escalation_success/escalation_success.py
+++ b/deepteam/metrics/agentic/escalation_success/escalation_success.py
@@ -50,7 +50,7 @@ class EscalationSuccessMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class EscalationSuccessMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class EscalationSuccessMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class EscalationSuccessMetric(BaseRedTeamingMetric):
prompt = EscalationSuccessTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class EscalationSuccessMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class EscalationSuccessMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/extraction_success/extraction_success.py b/deepteam/metrics/agentic/extraction_success/extraction_success.py
index 2e3f6142..a866db49 100644
--- a/deepteam/metrics/agentic/extraction_success/extraction_success.py
+++ b/deepteam/metrics/agentic/extraction_success/extraction_success.py
@@ -50,7 +50,7 @@ class ExtractionSuccessMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class ExtractionSuccessMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class ExtractionSuccessMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class ExtractionSuccessMetric(BaseRedTeamingMetric):
prompt = ExtractionSuccessTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class ExtractionSuccessMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class ExtractionSuccessMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/goal_drift/goal_drift.py b/deepteam/metrics/agentic/goal_drift/goal_drift.py
index 4920235f..4c1e0689 100644
--- a/deepteam/metrics/agentic/goal_drift/goal_drift.py
+++ b/deepteam/metrics/agentic/goal_drift/goal_drift.py
@@ -50,7 +50,7 @@ class GoalDriftMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class GoalDriftMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class GoalDriftMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class GoalDriftMetric(BaseRedTeamingMetric):
prompt = GoalDriftTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class GoalDriftMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class GoalDriftMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/hallucination_detection/hallucination_detection.py b/deepteam/metrics/agentic/hallucination_detection/hallucination_detection.py
index 7769cb79..3f8f6a14 100644
--- a/deepteam/metrics/agentic/hallucination_detection/hallucination_detection.py
+++ b/deepteam/metrics/agentic/hallucination_detection/hallucination_detection.py
@@ -50,7 +50,7 @@ class HallucinationDetectionMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class HallucinationDetectionMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -98,7 +98,8 @@ class HallucinationDetectionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class HallucinationDetectionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -162,7 +164,8 @@ class HallucinationDetectionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -201,7 +204,8 @@ class HallucinationDetectionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/hierarchy_consistency/hierarchy_consistency.py b/deepteam/metrics/agentic/hierarchy_consistency/hierarchy_consistency.py
index c6773b53..316b3e31 100644
--- a/deepteam/metrics/agentic/hierarchy_consistency/hierarchy_consistency.py
+++ b/deepteam/metrics/agentic/hierarchy_consistency/hierarchy_consistency.py
@@ -50,7 +50,7 @@ class HierarchyConsistencyMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class HierarchyConsistencyMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -98,7 +98,8 @@ class HierarchyConsistencyMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class HierarchyConsistencyMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -162,7 +164,8 @@ class HierarchyConsistencyMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -201,7 +204,8 @@ class HierarchyConsistencyMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/leakage_rate/leakage_rate.py b/deepteam/metrics/agentic/leakage_rate/leakage_rate.py
index 543d114b..177682da 100644
--- a/deepteam/metrics/agentic/leakage_rate/leakage_rate.py
+++ b/deepteam/metrics/agentic/leakage_rate/leakage_rate.py
@@ -50,7 +50,7 @@ class LeakageRateMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class LeakageRateMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class LeakageRateMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class LeakageRateMetric(BaseRedTeamingMetric):
prompt = LeakageRateTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class LeakageRateMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class LeakageRateMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/manipulation_assessment/manipulation_assessment.py b/deepteam/metrics/agentic/manipulation_assessment/manipulation_assessment.py
index 41b9c41b..3c576f3b 100644
--- a/deepteam/metrics/agentic/manipulation_assessment/manipulation_assessment.py
+++ b/deepteam/metrics/agentic/manipulation_assessment/manipulation_assessment.py
@@ -50,7 +50,7 @@ class ManipulationAssessmentMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class ManipulationAssessmentMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -98,7 +98,8 @@ class ManipulationAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class ManipulationAssessmentMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -162,7 +164,8 @@ class ManipulationAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -201,7 +204,8 @@ class ManipulationAssessmentMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/misinterpretation/misinterpretation.py b/deepteam/metrics/agentic/misinterpretation/misinterpretation.py
index de7c9098..61f4c74a 100644
--- a/deepteam/metrics/agentic/misinterpretation/misinterpretation.py
+++ b/deepteam/metrics/agentic/misinterpretation/misinterpretation.py
@@ -50,7 +50,7 @@ class MisinterpretationMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class MisinterpretationMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class MisinterpretationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class MisinterpretationMetric(BaseRedTeamingMetric):
prompt = MisinterpretationTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class MisinterpretationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class MisinterpretationMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/poisoning_assessment/poisoning_assessment.py b/deepteam/metrics/agentic/poisoning_assessment/poisoning_assessment.py
index 78be962c..d20032bd 100644
--- a/deepteam/metrics/agentic/poisoning_assessment/poisoning_assessment.py
+++ b/deepteam/metrics/agentic/poisoning_assessment/poisoning_assessment.py
@@ -50,7 +50,7 @@ class PoisoningAssessmentMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class PoisoningAssessmentMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class PoisoningAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class PoisoningAssessmentMetric(BaseRedTeamingMetric):
prompt = PoisoningAssessmentTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class PoisoningAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class PoisoningAssessmentMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/subversion_success/subversion_success.py b/deepteam/metrics/agentic/subversion_success/subversion_success.py
index 3a3b8157..8020526b 100644
--- a/deepteam/metrics/agentic/subversion_success/subversion_success.py
+++ b/deepteam/metrics/agentic/subversion_success/subversion_success.py
@@ -51,7 +51,7 @@ class SubversionSuccessMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -75,7 +75,7 @@ class SubversionSuccessMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -97,7 +97,8 @@ class SubversionSuccessMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -116,7 +117,8 @@ class SubversionSuccessMetric(BaseRedTeamingMetric):
prompt = SubversionSuccessTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -185,7 +187,8 @@ class SubversionSuccessMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -250,7 +253,8 @@ class SubversionSuccessMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/temporal_assessment/temporal_assessment.py b/deepteam/metrics/agentic/temporal_assessment/temporal_assessment.py
index b06a6751..2b3da19c 100644
--- a/deepteam/metrics/agentic/temporal_assessment/temporal_assessment.py
+++ b/deepteam/metrics/agentic/temporal_assessment/temporal_assessment.py
@@ -50,7 +50,7 @@ class TemporalAssessmentMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class TemporalAssessmentMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class TemporalAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class TemporalAssessmentMetric(BaseRedTeamingMetric):
prompt = TemporalAssessmentTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class TemporalAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class TemporalAssessmentMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/unauthorized_execution/unauthorized_execution.py b/deepteam/metrics/agentic/unauthorized_execution/unauthorized_execution.py
index 5ec7b106..283fc734 100644
--- a/deepteam/metrics/agentic/unauthorized_execution/unauthorized_execution.py
+++ b/deepteam/metrics/agentic/unauthorized_execution/unauthorized_execution.py
@@ -50,7 +50,7 @@ class UnauthorizedExecutionMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class UnauthorizedExecutionMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -98,7 +98,8 @@ class UnauthorizedExecutionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class UnauthorizedExecutionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -162,7 +164,8 @@ class UnauthorizedExecutionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -201,7 +204,8 @@ class UnauthorizedExecutionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/agentic/verification_assessment/verification_assessment.py b/deepteam/metrics/agentic/verification_assessment/verification_assessment.py
index 355512fa..b7548603 100644
--- a/deepteam/metrics/agentic/verification_assessment/verification_assessment.py
+++ b/deepteam/metrics/agentic/verification_assessment/verification_assessment.py
@@ -50,7 +50,7 @@ class VerificationAssessmentMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class VerificationAssessmentMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -98,7 +98,8 @@ class VerificationAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class VerificationAssessmentMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -162,7 +164,8 @@ class VerificationAssessmentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -201,7 +204,8 @@ class VerificationAssessmentMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/autonomous_agent_drift/autonomous_agent_drift.py b/deepteam/metrics/autonomous_agent_drift/autonomous_agent_drift.py
index 584797cf..8ea4ac02 100644
--- a/deepteam/metrics/autonomous_agent_drift/autonomous_agent_drift.py
+++ b/deepteam/metrics/autonomous_agent_drift/autonomous_agent_drift.py
@@ -52,7 +52,7 @@ class AutonomousAgentDriftMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -78,7 +78,7 @@ class AutonomousAgentDriftMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -153,7 +153,8 @@ class AutonomousAgentDriftMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -219,7 +220,8 @@ class AutonomousAgentDriftMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/bfla/bfla.py b/deepteam/metrics/bfla/bfla.py
index 25f966be..35e9b1ea 100644
--- a/deepteam/metrics/bfla/bfla.py
+++ b/deepteam/metrics/bfla/bfla.py
@@ -49,7 +49,7 @@ class BFLAMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -75,7 +75,7 @@ class BFLAMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -101,7 +101,8 @@ class BFLAMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -120,7 +121,8 @@ class BFLAMetric(BaseRedTeamingMetric):
prompt = BFLATemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -189,7 +191,8 @@ class BFLAMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -254,7 +257,8 @@ class BFLAMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/bias/bias.py b/deepteam/metrics/bias/bias.py
index c7bf4d18..204b05d6 100644
--- a/deepteam/metrics/bias/bias.py
+++ b/deepteam/metrics/bias/bias.py
@@ -50,7 +50,7 @@ class BiasMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class BiasMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class BiasMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class BiasMetric(BaseRedTeamingMetric):
prompt = BiasTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class BiasMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class BiasMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/bola/bola.py b/deepteam/metrics/bola/bola.py
index cddff93d..80e11062 100644
--- a/deepteam/metrics/bola/bola.py
+++ b/deepteam/metrics/bola/bola.py
@@ -49,7 +49,7 @@ class BOLAMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -76,7 +76,7 @@ class BOLAMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -101,7 +101,8 @@ class BOLAMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Entities
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.entities
else:
try:
@@ -118,7 +119,8 @@ class BOLAMetric(BaseRedTeamingMetric):
prompt = BOLATemplate.extract_entities(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Entities)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.entities
else:
try:
@@ -187,7 +189,8 @@ class BOLAMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -252,7 +255,8 @@ class BOLAMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/child_protection/child_protection.py b/deepteam/metrics/child_protection/child_protection.py
index fec88da6..cfce754e 100644
--- a/deepteam/metrics/child_protection/child_protection.py
+++ b/deepteam/metrics/child_protection/child_protection.py
@@ -50,7 +50,7 @@ class ChildProtectionMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class ChildProtectionMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class ChildProtectionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class ChildProtectionMetric(BaseRedTeamingMetric):
prompt = ChildProtectionTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -158,7 +160,8 @@ class ChildProtectionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -197,7 +200,8 @@ class ChildProtectionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/competitors/competitors.py b/deepteam/metrics/competitors/competitors.py
index 564ac419..49f30ae2 100644
--- a/deepteam/metrics/competitors/competitors.py
+++ b/deepteam/metrics/competitors/competitors.py
@@ -48,7 +48,7 @@ class CompetitorsMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class CompetitorsMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -100,7 +100,8 @@ class CompetitorsMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class CompetitorsMetric(BaseRedTeamingMetric):
prompt = CompetitorsTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -162,7 +164,8 @@ class CompetitorsMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -201,7 +204,8 @@ class CompetitorsMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/contracts/contracts.py b/deepteam/metrics/contracts/contracts.py
index 4ce80c4c..a26884a0 100644
--- a/deepteam/metrics/contracts/contracts.py
+++ b/deepteam/metrics/contracts/contracts.py
@@ -44,7 +44,7 @@ class ContractsMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -70,7 +70,7 @@ class ContractsMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -117,7 +117,8 @@ class ContractsMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -154,7 +155,8 @@ class ContractsMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/cross_context_retrieval/cross_context_retrieval.py b/deepteam/metrics/cross_context_retrieval/cross_context_retrieval.py
index 2eb722fe..540e7f12 100644
--- a/deepteam/metrics/cross_context_retrieval/cross_context_retrieval.py
+++ b/deepteam/metrics/cross_context_retrieval/cross_context_retrieval.py
@@ -50,7 +50,7 @@ class CrossContextRetrievalMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class CrossContextRetrievalMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -98,7 +98,8 @@ class CrossContextRetrievalMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class CrossContextRetrievalMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -188,7 +190,8 @@ class CrossContextRetrievalMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -253,7 +256,8 @@ class CrossContextRetrievalMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/debug_access/debug_access.py b/deepteam/metrics/debug_access/debug_access.py
index ccb2f9b5..9256d991 100644
--- a/deepteam/metrics/debug_access/debug_access.py
+++ b/deepteam/metrics/debug_access/debug_access.py
@@ -44,7 +44,7 @@ class DebugAccessMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -70,7 +70,7 @@ class DebugAccessMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -117,7 +117,8 @@ class DebugAccessMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -155,7 +156,8 @@ class DebugAccessMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/ethics/ethics.py b/deepteam/metrics/ethics/ethics.py
index 16cf216a..44753465 100644
--- a/deepteam/metrics/ethics/ethics.py
+++ b/deepteam/metrics/ethics/ethics.py
@@ -48,7 +48,7 @@ class EthicsMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -72,7 +72,7 @@ class EthicsMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -94,7 +94,8 @@ class EthicsMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -113,7 +114,8 @@ class EthicsMetric(BaseRedTeamingMetric):
prompt = EthicsTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -156,7 +158,8 @@ class EthicsMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -195,7 +198,8 @@ class EthicsMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/excessive_agency/excessive_agency.py b/deepteam/metrics/excessive_agency/excessive_agency.py
index fd333182..0cf00010 100644
--- a/deepteam/metrics/excessive_agency/excessive_agency.py
+++ b/deepteam/metrics/excessive_agency/excessive_agency.py
@@ -47,7 +47,7 @@ class ExcessiveAgencyMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -73,7 +73,7 @@ class ExcessiveAgencyMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -147,7 +147,8 @@ class ExcessiveAgencyMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -212,7 +213,8 @@ class ExcessiveAgencyMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/exploit_tool_agent/exploit_tool_agent.py b/deepteam/metrics/exploit_tool_agent/exploit_tool_agent.py
index da5f7807..96a8fe2e 100644
--- a/deepteam/metrics/exploit_tool_agent/exploit_tool_agent.py
+++ b/deepteam/metrics/exploit_tool_agent/exploit_tool_agent.py
@@ -50,7 +50,7 @@ class ExploitToolAgentMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class ExploitToolAgentMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class ExploitToolAgentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class ExploitToolAgentMetric(BaseRedTeamingMetric):
prompt = ExploitToolAgentTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -184,7 +186,8 @@ class ExploitToolAgentMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -249,7 +252,8 @@ class ExploitToolAgentMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/external_system_abuse/external_system_abuse.py b/deepteam/metrics/external_system_abuse/external_system_abuse.py
index ffca64db..3e9fa925 100644
--- a/deepteam/metrics/external_system_abuse/external_system_abuse.py
+++ b/deepteam/metrics/external_system_abuse/external_system_abuse.py
@@ -50,7 +50,7 @@ class ExternalSystemAbuseMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class ExternalSystemAbuseMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -96,7 +96,8 @@ class ExternalSystemAbuseMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -115,7 +116,8 @@ class ExternalSystemAbuseMetric(BaseRedTeamingMetric):
prompt = ExternalSystemAbuseTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -185,7 +187,8 @@ class ExternalSystemAbuseMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -250,7 +253,8 @@ class ExternalSystemAbuseMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/fairness/fairness.py b/deepteam/metrics/fairness/fairness.py
index 931f711a..cebab317 100644
--- a/deepteam/metrics/fairness/fairness.py
+++ b/deepteam/metrics/fairness/fairness.py
@@ -48,7 +48,7 @@ class FairnessMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -72,7 +72,7 @@ class FairnessMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -94,7 +94,8 @@ class FairnessMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -113,7 +114,8 @@ class FairnessMetric(BaseRedTeamingMetric):
prompt = FairnessTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -156,7 +158,8 @@ class FairnessMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -195,7 +198,8 @@ class FairnessMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/graphic_content/graphic_content.py b/deepteam/metrics/graphic_content/graphic_content.py
index e19461fe..b376fe78 100644
--- a/deepteam/metrics/graphic_content/graphic_content.py
+++ b/deepteam/metrics/graphic_content/graphic_content.py
@@ -49,7 +49,7 @@ class GraphicMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -75,7 +75,7 @@ class GraphicMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -124,7 +124,8 @@ class GraphicMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -164,7 +165,8 @@ class GraphicMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/hallucination/hallucination.py b/deepteam/metrics/hallucination/hallucination.py
index 3b45eb9a..30482151 100644
--- a/deepteam/metrics/hallucination/hallucination.py
+++ b/deepteam/metrics/hallucination/hallucination.py
@@ -48,7 +48,7 @@ class HallucinationMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class HallucinationMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -100,7 +100,8 @@ class HallucinationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class HallucinationMetric(BaseRedTeamingMetric):
prompt = HallucinationTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -162,7 +164,8 @@ class HallucinationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -201,7 +204,8 @@ class HallucinationMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/harm/harm.py b/deepteam/metrics/harm/harm.py
index 21a48882..2081fa51 100644
--- a/deepteam/metrics/harm/harm.py
+++ b/deepteam/metrics/harm/harm.py
@@ -45,7 +45,7 @@ class HarmMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -71,7 +71,7 @@ class HarmMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -119,7 +119,8 @@ class HarmMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -158,7 +159,8 @@ class HarmMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/hijacking/hijacking.py b/deepteam/metrics/hijacking/hijacking.py
index 72d3ca8c..cd365e75 100644
--- a/deepteam/metrics/hijacking/hijacking.py
+++ b/deepteam/metrics/hijacking/hijacking.py
@@ -46,7 +46,7 @@ class HijackingMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -72,7 +72,7 @@ class HijackingMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -98,7 +98,8 @@ class HijackingMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -117,7 +118,8 @@ class HijackingMetric(BaseRedTeamingMetric):
prompt = HijackingTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -160,7 +162,8 @@ class HijackingMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -199,7 +202,8 @@ class HijackingMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/illegal_activity/illegal_activity.py b/deepteam/metrics/illegal_activity/illegal_activity.py
index b9d0b6eb..f17d6509 100644
--- a/deepteam/metrics/illegal_activity/illegal_activity.py
+++ b/deepteam/metrics/illegal_activity/illegal_activity.py
@@ -49,7 +49,7 @@ class IllegalMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -75,7 +75,7 @@ class IllegalMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -124,7 +124,8 @@ class IllegalMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -164,7 +165,8 @@ class IllegalMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/imitation/imitation.py b/deepteam/metrics/imitation/imitation.py
index 8622b3ab..9f47684c 100644
--- a/deepteam/metrics/imitation/imitation.py
+++ b/deepteam/metrics/imitation/imitation.py
@@ -48,7 +48,7 @@ class ImitationMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -75,7 +75,7 @@ class ImitationMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -100,7 +100,8 @@ class ImitationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Entities
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.entities
else:
try:
@@ -117,7 +118,8 @@ class ImitationMetric(BaseRedTeamingMetric):
prompt = ImitationTemplate.extract_entities(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Entities)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.entities
else:
try:
@@ -160,7 +162,8 @@ class ImitationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -199,7 +202,8 @@ class ImitationMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/indirect_instruction/indirect_instruction.py b/deepteam/metrics/indirect_instruction/indirect_instruction.py
index 8c65a063..e2666bb0 100644
--- a/deepteam/metrics/indirect_instruction/indirect_instruction.py
+++ b/deepteam/metrics/indirect_instruction/indirect_instruction.py
@@ -52,7 +52,7 @@ class IndirectInstructionMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -78,7 +78,7 @@ class IndirectInstructionMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -153,7 +153,8 @@ class IndirectInstructionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -219,7 +220,8 @@ class IndirectInstructionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/insecure_inter_agent_communication/insecure_inter_agent_communication.py b/deepteam/metrics/insecure_inter_agent_communication/insecure_inter_agent_communication.py
index 2902a04c..f9d1a0cf 100644
--- a/deepteam/metrics/insecure_inter_agent_communication/insecure_inter_agent_communication.py
+++ b/deepteam/metrics/insecure_inter_agent_communication/insecure_inter_agent_communication.py
@@ -51,7 +51,7 @@ class InsecureInterAgentCommunicationMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -77,7 +77,7 @@ class InsecureInterAgentCommunicationMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -128,7 +128,8 @@ class InsecureInterAgentCommunicationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -170,7 +171,8 @@ class InsecureInterAgentCommunicationMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/intellectual_property/intellectual_property.py b/deepteam/metrics/intellectual_property/intellectual_property.py
index 401cf4ee..5e90315d 100644
--- a/deepteam/metrics/intellectual_property/intellectual_property.py
+++ b/deepteam/metrics/intellectual_property/intellectual_property.py
@@ -46,7 +46,7 @@ class IntellectualPropertyMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -72,7 +72,7 @@ class IntellectualPropertyMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -100,7 +100,8 @@ class IntellectualPropertyMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -121,7 +122,8 @@ class IntellectualPropertyMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -163,7 +165,8 @@ class IntellectualPropertyMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -201,7 +204,8 @@ class IntellectualPropertyMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/misinformation/misinformation.py b/deepteam/metrics/misinformation/misinformation.py
index 32096589..7579004c 100644
--- a/deepteam/metrics/misinformation/misinformation.py
+++ b/deepteam/metrics/misinformation/misinformation.py
@@ -49,7 +49,7 @@ class MisinformationMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -75,7 +75,7 @@ class MisinformationMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -124,7 +124,8 @@ class MisinformationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -164,7 +165,8 @@ class MisinformationMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/overreliance/overreliance.py b/deepteam/metrics/overreliance/overreliance.py
index cb71d790..7e730b3a 100644
--- a/deepteam/metrics/overreliance/overreliance.py
+++ b/deepteam/metrics/overreliance/overreliance.py
@@ -48,7 +48,7 @@ class OverrelianceMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class OverrelianceMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -100,7 +100,8 @@ class OverrelianceMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class OverrelianceMetric(BaseRedTeamingMetric):
prompt = OverrelianceTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -162,7 +164,8 @@ class OverrelianceMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -201,7 +204,8 @@ class OverrelianceMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/personal_safety/personal_safety.py b/deepteam/metrics/personal_safety/personal_safety.py
index 5ed063e9..777b4341 100644
--- a/deepteam/metrics/personal_safety/personal_safety.py
+++ b/deepteam/metrics/personal_safety/personal_safety.py
@@ -51,7 +51,7 @@ class SafetyMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -77,7 +77,7 @@ class SafetyMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -126,7 +126,8 @@ class SafetyMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -166,7 +167,8 @@ class SafetyMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/pii/pii.py b/deepteam/metrics/pii/pii.py
index ea97a295..22df7006 100644
--- a/deepteam/metrics/pii/pii.py
+++ b/deepteam/metrics/pii/pii.py
@@ -48,7 +48,7 @@ class PIIMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -76,7 +76,7 @@ class PIIMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -104,7 +104,8 @@ class PIIMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -123,7 +124,8 @@ class PIIMetric(BaseRedTeamingMetric):
prompt = PIITemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -142,7 +144,8 @@ class PIIMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Entities
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.entities
else:
try:
@@ -159,7 +162,8 @@ class PIIMetric(BaseRedTeamingMetric):
prompt = PIITemplate.extract_entities(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Entities)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.entities
else:
try:
@@ -203,7 +207,8 @@ class PIIMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -243,7 +248,8 @@ class PIIMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/prompt_extraction/prompt_extraction.py b/deepteam/metrics/prompt_extraction/prompt_extraction.py
index b40ab745..a5f99129 100644
--- a/deepteam/metrics/prompt_extraction/prompt_extraction.py
+++ b/deepteam/metrics/prompt_extraction/prompt_extraction.py
@@ -46,7 +46,7 @@ class PromptExtractionMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -72,7 +72,7 @@ class PromptExtractionMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -98,7 +98,8 @@ class PromptExtractionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -117,7 +118,8 @@ class PromptExtractionMetric(BaseRedTeamingMetric):
prompt = PromptExtractionTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -160,7 +162,8 @@ class PromptExtractionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -199,7 +202,8 @@ class PromptExtractionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/rbac/rbac.py b/deepteam/metrics/rbac/rbac.py
index 041fc59d..d271d4ca 100644
--- a/deepteam/metrics/rbac/rbac.py
+++ b/deepteam/metrics/rbac/rbac.py
@@ -49,7 +49,7 @@ class RBACMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -76,7 +76,7 @@ class RBACMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -151,7 +151,8 @@ class RBACMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -216,7 +217,8 @@ class RBACMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -237,7 +239,8 @@ class RBACMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -256,7 +259,8 @@ class RBACMetric(BaseRedTeamingMetric):
prompt = RBACTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
diff --git a/deepteam/metrics/shell_injection/shell_injection.py b/deepteam/metrics/shell_injection/shell_injection.py
index 9352b94e..84ad1111 100644
--- a/deepteam/metrics/shell_injection/shell_injection.py
+++ b/deepteam/metrics/shell_injection/shell_injection.py
@@ -45,7 +45,7 @@ class ShellInjectionMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -71,7 +71,7 @@ class ShellInjectionMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -144,7 +144,8 @@ class ShellInjectionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -208,7 +209,8 @@ class ShellInjectionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/sql_injection/sql_injection.py b/deepteam/metrics/sql_injection/sql_injection.py
index f83e853a..df470e57 100644
--- a/deepteam/metrics/sql_injection/sql_injection.py
+++ b/deepteam/metrics/sql_injection/sql_injection.py
@@ -45,7 +45,7 @@ class SQLInjectionMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -69,7 +69,7 @@ class SQLInjectionMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -142,7 +142,8 @@ class SQLInjectionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -206,7 +207,8 @@ class SQLInjectionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/ssrf/ssrf.py b/deepteam/metrics/ssrf/ssrf.py
index a7382f4a..1df5641a 100644
--- a/deepteam/metrics/ssrf/ssrf.py
+++ b/deepteam/metrics/ssrf/ssrf.py
@@ -49,7 +49,7 @@ class SSRFMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -75,7 +75,7 @@ class SSRFMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -101,7 +101,8 @@ class SSRFMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -120,7 +121,8 @@ class SSRFMetric(BaseRedTeamingMetric):
prompt = SSRFTemplate.extract_purpose(self.system_prompt)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -189,7 +191,8 @@ class SSRFMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -254,7 +257,8 @@ class SSRFMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/system_reconnaissance/system_reconnaissance.py b/deepteam/metrics/system_reconnaissance/system_reconnaissance.py
index 6f01dac1..27079e8f 100644
--- a/deepteam/metrics/system_reconnaissance/system_reconnaissance.py
+++ b/deepteam/metrics/system_reconnaissance/system_reconnaissance.py
@@ -50,7 +50,7 @@ class SystemReconnaissanceMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -74,7 +74,7 @@ class SystemReconnaissanceMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self, async_mode=True, _show_indicator=_show_indicator
):
@@ -98,7 +98,8 @@ class SystemReconnaissanceMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=Purpose
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -119,7 +120,8 @@ class SystemReconnaissanceMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=Purpose)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.purpose
else:
try:
@@ -188,7 +190,8 @@ class SystemReconnaissanceMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -253,7 +256,8 @@ class SystemReconnaissanceMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/tool_metadata_poisoning/tool_metadata_poisoning.py b/deepteam/metrics/tool_metadata_poisoning/tool_metadata_poisoning.py
index a4c6b03b..7d4bae4d 100644
--- a/deepteam/metrics/tool_metadata_poisoning/tool_metadata_poisoning.py
+++ b/deepteam/metrics/tool_metadata_poisoning/tool_metadata_poisoning.py
@@ -52,7 +52,7 @@ class ToolMetadataPoisoningMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -78,7 +78,7 @@ class ToolMetadataPoisoningMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -153,7 +153,8 @@ class ToolMetadataPoisoningMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -219,7 +220,8 @@ class ToolMetadataPoisoningMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/tool_orchestration/tool_orchestration.py b/deepteam/metrics/tool_orchestration/tool_orchestration.py
index d597b41e..4ae52f22 100644
--- a/deepteam/metrics/tool_orchestration/tool_orchestration.py
+++ b/deepteam/metrics/tool_orchestration/tool_orchestration.py
@@ -52,7 +52,7 @@ class ToolOrchestrationMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -78,7 +78,7 @@ class ToolOrchestrationMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -153,7 +153,8 @@ class ToolOrchestrationMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -219,7 +220,8 @@ class ToolOrchestrationMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/toxicity/toxicity.py b/deepteam/metrics/toxicity/toxicity.py
index d87a3c57..2f67d11f 100644
--- a/deepteam/metrics/toxicity/toxicity.py
+++ b/deepteam/metrics/toxicity/toxicity.py
@@ -49,7 +49,7 @@ class ToxicityMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -75,7 +75,7 @@ class ToxicityMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -124,7 +124,8 @@ class ToxicityMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -164,7 +165,8 @@ class ToxicityMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
diff --git a/deepteam/metrics/unexpected_code_execution/unexpected_code_execution.py b/deepteam/metrics/unexpected_code_execution/unexpected_code_execution.py
index 0336426a..b803fa0e 100644
--- a/deepteam/metrics/unexpected_code_execution/unexpected_code_execution.py
+++ b/deepteam/metrics/unexpected_code_execution/unexpected_code_execution.py
@@ -52,7 +52,7 @@ class UnexpectedCodeExecutionMetric(BaseRedTeamingMetric):
def measure(self, test_case: RTTestCase) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(self, _show_indicator=False):
if self.async_mode:
loop = get_or_create_event_loop()
@@ -78,7 +78,7 @@ class UnexpectedCodeExecutionMetric(BaseRedTeamingMetric):
_show_indicator: bool = False,
) -> float:
- self.evaluation_cost = 0 if self.using_native_model else None
+ self.evaluation_cost = None
with metric_progress_indicator(
self,
async_mode=True,
@@ -153,7 +153,8 @@ class UnexpectedCodeExecutionMetric(BaseRedTeamingMetric):
res, cost = await self.model.a_generate(
prompt=prompt, schema=ReasonScore
)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try:
@@ -219,7 +220,8 @@ class UnexpectedCodeExecutionMetric(BaseRedTeamingMetric):
)
if self.using_native_model:
res, cost = self.model.generate(prompt=prompt, schema=ReasonScore)
- self.evaluation_cost += cost
+ if cost is not None:
+ self.evaluation_cost = (self.evaluation_cost or 0) + cost
return res.score, res.reason
else:
try: