Spaces:
Sleeping
Sleeping
Commit ·
5016a17
1
Parent(s): 2112542
add grader endpoint
Browse files- sql_env/server.py +24 -1
sql_env/server.py
CHANGED
|
@@ -123,4 +123,27 @@ def main():
|
|
| 123 |
|
| 124 |
|
| 125 |
if __name__ == "__main__":
|
| 126 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
if __name__ == "__main__":
|
| 126 |
+
main()
|
| 127 |
+
@app.post("/grader")
|
| 128 |
+
async def grader_endpoint(request: dict):
|
| 129 |
+
"""Grader endpoint called by validator to score a task directly."""
|
| 130 |
+
from sql_env.grader import grade
|
| 131 |
+
from sql_env.tasks import TASK_SETS
|
| 132 |
+
import random
|
| 133 |
+
|
| 134 |
+
task_name = request.get("task_name", "easy")
|
| 135 |
+
action_data = request.get("action", {})
|
| 136 |
+
corrected_query = action_data.get("corrected_query", "")
|
| 137 |
+
|
| 138 |
+
tasks = TASK_SETS.get(task_name, TASK_SETS["easy"])
|
| 139 |
+
task = random.choice(tasks)
|
| 140 |
+
|
| 141 |
+
action = SQLAction(corrected_query=corrected_query)
|
| 142 |
+
reward_obj = grade(action, task)
|
| 143 |
+
|
| 144 |
+
return {
|
| 145 |
+
"task_name": task_name,
|
| 146 |
+
"score": reward_obj.value,
|
| 147 |
+
"reason": reward_obj.reason,
|
| 148 |
+
"success": reward_obj.value >= 0.95,
|
| 149 |
+
}
|