Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions akd/agents/risk/risk.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Dict, List, Optional, Self
from typing import Any, Dict, List, Optional, Self

import yaml
from deepeval.metrics import DAGMetric
Expand Down Expand Up @@ -66,11 +66,7 @@ def check_inputs(self) -> Self:
raise ValueError(
f"risk_weights keys {sorted(extra)} are not in risk_ids {sorted(self.risk_ids)}",
)
nonpos = {
k: v
for k, v in self.risk_weights.items()
if not (isinstance(v, (int, float)) and v > 0)
}
nonpos = {k: v for k, v in self.risk_weights.items() if not (isinstance(v, (int, float)) and v > 0)}
if nonpos:
raise ValueError(
f"risk_weights must be positive numbers; got {nonpos}",
Expand Down Expand Up @@ -115,7 +111,7 @@ class RiskAgentOutputSchema(OutputSchema):
...,
description="A mapping of risk IDs to sructured evaluation criteria.",
)
dag_metric: DAGMetric = Field(
dag_metric: Optional[Any] = Field(
...,
description="A DeepEval DAG metric constructed from the risk criteria.",
)
Expand Down Expand Up @@ -288,9 +284,7 @@ def build_dag_from_criteria(

node = TaskNode(
output_label=f"{risk_id}_{i + 1}",
instructions=(
f"{criterion.description}\nAnswer strictly with True or False."
),
instructions=(f"{criterion.description}\nAnswer strictly with True or False."),
evaluation_params=[
LLMTestCaseParams.INPUT,
LLMTestCaseParams.ACTUAL_OUTPUT,
Expand Down Expand Up @@ -318,8 +312,7 @@ def build_dag_from_criteria(
m_required = (m_total + 1) // 2 # ceil
# Borderline = exactly one below required (only meaningful if m_total > 0)
borderline_expr = (
"True if the count of True among the MEDIUM set equals "
f"{max(m_required - 1, 0)}; otherwise False."
f"True if the count of True among the MEDIUM set equals {max(m_required - 1, 0)}; otherwise False."
if m_total > 0
else "False"
)
Expand Down
Loading