Spaces:
Runtime error
Runtime error
Update server/tasks.py
Browse files- server/tasks.py +46 -61
server/tasks.py
CHANGED
|
@@ -45,7 +45,7 @@ class TaskSpec:
|
|
| 45 |
queries: tuple[QuerySpec, ...]
|
| 46 |
large_model_penalty: float = 0.0
|
| 47 |
description: str = ""
|
| 48 |
-
|
| 49 |
|
| 50 |
|
| 51 |
TASKS: dict[str, TaskSpec] = {
|
|
@@ -60,7 +60,7 @@ TASKS: dict[str, TaskSpec] = {
|
|
| 60 |
),
|
| 61 |
),
|
| 62 |
description="Single-query routing with accuracy-only emphasis.",
|
| 63 |
-
grader="grade_task_1", #
|
| 64 |
),
|
| 65 |
"task_2": TaskSpec(
|
| 66 |
task_id="task_2",
|
|
@@ -72,87 +72,72 @@ TASKS: dict[str, TaskSpec] = {
|
|
| 72 |
minimum_model=ModelChoice.SMALL,
|
| 73 |
),
|
| 74 |
QuerySpec(
|
| 75 |
-
text="
|
| 76 |
-
correct_answer="
|
| 77 |
-
minimum_model=ModelChoice.
|
| 78 |
-
),
|
| 79 |
-
QuerySpec(
|
| 80 |
-
text="Design a safety fallback for multilingual medical triage.",
|
| 81 |
-
correct_answer="Use high-capability review with escalation and verified retrieval before final output.",
|
| 82 |
-
minimum_model=ModelChoice.LARGE,
|
| 83 |
),
|
| 84 |
),
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
grader="grade_task_2",
|
| 88 |
),
|
| 89 |
"task_3": TaskSpec(
|
| 90 |
task_id="task_3",
|
| 91 |
difficulty="hard",
|
| 92 |
queries=(
|
| 93 |
QuerySpec(
|
| 94 |
-
text="
|
| 95 |
-
correct_answer="
|
| 96 |
minimum_model=ModelChoice.SMALL,
|
| 97 |
-
kb_available=True,
|
| 98 |
),
|
| 99 |
QuerySpec(
|
| 100 |
-
text="
|
| 101 |
-
correct_answer="
|
| 102 |
minimum_model=ModelChoice.MEDIUM,
|
| 103 |
),
|
| 104 |
QuerySpec(
|
| 105 |
-
text="
|
| 106 |
-
correct_answer="
|
| 107 |
-
minimum_model=ModelChoice.SMALL,
|
| 108 |
-
kb_available=True,
|
| 109 |
-
),
|
| 110 |
-
QuerySpec(
|
| 111 |
-
text="Generate a compliant answer for a finance-regulated enterprise user.",
|
| 112 |
-
correct_answer="Use the large model with a retrieval-backed compliance layer.",
|
| 113 |
-
minimum_model=ModelChoice.LARGE,
|
| 114 |
-
),
|
| 115 |
-
QuerySpec(
|
| 116 |
-
text="Route a long-form reasoning question about carbon-aware serving policy.",
|
| 117 |
-
correct_answer="Use cascade with escalation to a larger model if smaller ones fail.",
|
| 118 |
minimum_model=ModelChoice.MEDIUM,
|
| 119 |
),
|
| 120 |
),
|
| 121 |
-
description="
|
| 122 |
-
grader="grade_task_3",
|
| 123 |
),
|
| 124 |
}
|
| 125 |
|
| 126 |
-
|
| 127 |
-
"
|
| 128 |
-
"
|
| 129 |
-
"
|
| 130 |
}
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
def get_task(task_id: str) -> TaskSpec:
|
| 134 |
-
"""
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
if task_spec is None:
|
| 149 |
-
raise ValueError(f"Unknown task id: {task_id}. Available tasks: {list(TASKS.keys())}")
|
| 150 |
-
|
| 151 |
-
return task_spec
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
TASK_REGISTRY = TASKS # Alias for app.py compatibility
|
| 155 |
-
|
| 156 |
-
# Expose grader mappings for registration
|
| 157 |
-
from server.graders import GRADERS
|
| 158 |
|
|
|
|
| 45 |
queries: tuple[QuerySpec, ...]
|
| 46 |
large_model_penalty: float = 0.0
|
| 47 |
description: str = ""
|
| 48 |
+
grader: Optional[str] = None # Use actual grader function names
|
| 49 |
|
| 50 |
|
| 51 |
TASKS: dict[str, TaskSpec] = {
|
|
|
|
| 60 |
),
|
| 61 |
),
|
| 62 |
description="Single-query routing with accuracy-only emphasis.",
|
| 63 |
+
grader="grade_task_1", # ✅ Correct function name
|
| 64 |
),
|
| 65 |
"task_2": TaskSpec(
|
| 66 |
task_id="task_2",
|
|
|
|
| 72 |
minimum_model=ModelChoice.SMALL,
|
| 73 |
),
|
| 74 |
QuerySpec(
|
| 75 |
+
text="Evaluate whether aggressive quantization is suitable for a high-precision scientific task.",
|
| 76 |
+
correct_answer="Quantization is not suitable for high-precision scientific tasks.",
|
| 77 |
+
minimum_model=ModelChoice.SMALL,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
),
|
| 79 |
),
|
| 80 |
+
description="Two-query routing with accuracy and efficiency emphasis.",
|
| 81 |
+
grader="grade_task_2", # ✅ Correct function name
|
|
|
|
| 82 |
),
|
| 83 |
"task_3": TaskSpec(
|
| 84 |
task_id="task_3",
|
| 85 |
difficulty="hard",
|
| 86 |
queries=(
|
| 87 |
QuerySpec(
|
| 88 |
+
text="What is the most efficient way to handle energy-related billing complaints during a power outage?",
|
| 89 |
+
correct_answer="A cascade of escalation protocols with compliance checks.",
|
| 90 |
minimum_model=ModelChoice.SMALL,
|
|
|
|
| 91 |
),
|
| 92 |
QuerySpec(
|
| 93 |
+
text="Evaluate the impact of billing system latency on customer satisfaction.",
|
| 94 |
+
correct_answer="High billing system latency leads to customer dissatisfaction.",
|
| 95 |
minimum_model=ModelChoice.MEDIUM,
|
| 96 |
),
|
| 97 |
QuerySpec(
|
| 98 |
+
text="Describe how to handle a customer who complains about billing during a power outage.",
|
| 99 |
+
correct_answer="Implement a fallback billing system with manual verification.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
minimum_model=ModelChoice.MEDIUM,
|
| 101 |
),
|
| 102 |
),
|
| 103 |
+
description="Three-query routing with complexity emphasis.",
|
| 104 |
+
grader="grade_task_3", # ✅ Correct function name
|
| 105 |
),
|
| 106 |
}
|
| 107 |
|
| 108 |
+
TASK_REGISTRY: dict[str, str] = {
|
| 109 |
+
"task_1": "task_1",
|
| 110 |
+
"task_2": "task_2",
|
| 111 |
+
"task_3": "task_3",
|
| 112 |
}
|
| 113 |
|
| 114 |
+
# Import grader functions (note: use actual function names, not aliases)
|
| 115 |
+
from graders import grade_task_1, grade_task_2, grade_task_3, GRADERS
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# Helper to map difficulty to grader function
|
| 119 |
+
def get_grader_for_difficulty(difficulty: str) -> str:
|
| 120 |
+
"""Get the grader function name for a given difficulty level."""
|
| 121 |
+
difficulty_map = {
|
| 122 |
+
"easy": grade_task_1,
|
| 123 |
+
"medium": grade_task_2,
|
| 124 |
+
"hard": grade_task_3,
|
| 125 |
+
}
|
| 126 |
+
return difficulty_map.get(difficulty, grade_task_1)
|
| 127 |
+
|
| 128 |
|
| 129 |
def get_task(task_id: str) -> TaskSpec:
|
| 130 |
+
"""Retrieve a task by its ID."""
|
| 131 |
+
return TASKS.get(task_id)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def get_task_registry() -> dict[str, str]:
|
| 135 |
+
"""Return the task registry mapping task IDs to task names."""
|
| 136 |
+
return TASK_REGISTRY
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
# Re-export GRADERS for server usage
|
| 140 |
+
from server.app import GRADERS_REGISTRY
|
| 141 |
+
|
| 142 |
+
GRADERS_REGISTRY[task_id] = GRADERS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|