rudhratej09 commited on
Commit
42dbc8a
·
verified ·
1 Parent(s): 2cd5ba7

Update server/tasks.py

Browse files
Files changed (1) hide show
  1. 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
- graders: Optional[str] = None # grader function reference
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", # Reference grader function
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="Explain when speculative decoding improves throughput on medium-sized models.",
76
- correct_answer="It helps when draft tokens are likely to be accepted by the target model.",
77
- minimum_model=ModelChoice.MEDIUM,
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
- large_model_penalty=-0.2,
86
- description="Three-query episode with an extra penalty for using the LARGE model.",
87
- grader="grade_task_2",
88
  ),
89
  "task_3": TaskSpec(
90
  task_id="task_3",
91
  difficulty="hard",
92
  queries=(
93
  QuerySpec(
94
- text="Classify whether this FAQ request can be answered from the billing knowledge base.",
95
- correct_answer="Yes, use the billing KB article.",
96
  minimum_model=ModelChoice.SMALL,
97
- kb_available=True,
98
  ),
99
  QuerySpec(
100
- text="Route a long-form reasoning question about carbon-aware serving policy.",
101
- correct_answer="Use cascade with escalation to a larger model if smaller ones fail.",
102
  minimum_model=ModelChoice.MEDIUM,
103
  ),
104
  QuerySpec(
105
- text="Classify whether this FAQ request can be answered from the billing knowledge base.",
106
- correct_answer="Yes, use the billing KB article.",
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="Stateful five-query episode with repeats, caching, cascading, early exit, and waiting.",
122
- grader="grade_task_3",
123
  ),
124
  }
125
 
126
- TASK_ALIASES: dict[str, str] = {
127
- "easy": "task_1",
128
- "medium": "task_2",
129
- "hard": "task_3",
130
  }
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  def get_task(task_id: str) -> TaskSpec:
134
- """Return a task by id, defaulting to the easy task for unknown ids.
135
-
136
- Args:
137
- task_id: Task identifier (e.g., "task_1", "easy", "medium", "hard")
138
-
139
- Returns:
140
- TaskSpec for the requested task
141
-
142
- Raises:
143
- ValueError: If task not found and no default is set
144
- """
145
- resolved_task_id = TASK_ALIASES.get(task_id, task_id)
146
- task_spec = TASKS.get(resolved_task_id)
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