Add explicit grader classes and openenv task mappings
Browse files- AgentBox/openenv.yaml +13 -0
- AgentBox/server/__init__.py +6 -1
- AgentBox/server/graders.py +85 -0
- openenv.yaml +14 -1
- server/graders.py +1 -0
AgentBox/openenv.yaml
CHANGED
|
@@ -4,4 +4,17 @@ type: space
|
|
| 4 |
runtime: fastapi
|
| 5 |
app: src.env:app
|
| 6 |
port: 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
|
|
|
| 4 |
runtime: fastapi
|
| 5 |
app: src.env:app
|
| 6 |
port: 7860
|
| 7 |
+
tasks:
|
| 8 |
+
- id: easy_task
|
| 9 |
+
name: Easy Task
|
| 10 |
+
difficulty: easy
|
| 11 |
+
grader: server.graders:EasyGrader
|
| 12 |
+
- id: medium_task
|
| 13 |
+
name: Medium Task
|
| 14 |
+
difficulty: medium
|
| 15 |
+
grader: server.graders:MediumGrader
|
| 16 |
+
- id: hard_task
|
| 17 |
+
name: Hard Task
|
| 18 |
+
difficulty: hard
|
| 19 |
+
grader: server.graders:HardGrader
|
| 20 |
|
AgentBox/server/__init__.py
CHANGED
|
@@ -6,6 +6,11 @@
|
|
| 6 |
|
| 7 |
"""Agentbox environment server components."""
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
__all__ = ["AgentboxEnvironment"]
|
|
|
|
| 6 |
|
| 7 |
"""Agentbox environment server components."""
|
| 8 |
|
| 9 |
+
try:
|
| 10 |
+
from .AgentBox_environment import AgentboxEnvironment
|
| 11 |
+
except Exception: # pragma: no cover
|
| 12 |
+
# Keep package importable for tools that only need sibling modules
|
| 13 |
+
# such as `server.graders` during validation.
|
| 14 |
+
AgentboxEnvironment = None # type: ignore[assignment]
|
| 15 |
|
| 16 |
__all__ = ["AgentboxEnvironment"]
|
AgentBox/server/graders.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ast
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def _extract_text(payload: Any) -> str:
|
| 6 |
+
if payload is None:
|
| 7 |
+
return ""
|
| 8 |
+
if isinstance(payload, str):
|
| 9 |
+
return payload
|
| 10 |
+
if isinstance(payload, dict):
|
| 11 |
+
for key in ("candidate", "code", "action", "text", "output"):
|
| 12 |
+
value = payload.get(key)
|
| 13 |
+
if isinstance(value, str):
|
| 14 |
+
return value
|
| 15 |
+
return str(payload)
|
| 16 |
+
return str(payload)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class EasyGrader:
|
| 20 |
+
"""Easy: syntax/lint style signal."""
|
| 21 |
+
|
| 22 |
+
def grade(self, payload: Any) -> float:
|
| 23 |
+
text = _extract_text(payload)
|
| 24 |
+
if not text.strip():
|
| 25 |
+
return 0.10
|
| 26 |
+
try:
|
| 27 |
+
ast.parse(text)
|
| 28 |
+
return 0.90
|
| 29 |
+
except SyntaxError:
|
| 30 |
+
return 0.20
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class MediumGrader:
|
| 34 |
+
"""Medium: safety patch signal."""
|
| 35 |
+
|
| 36 |
+
_unsafe = ("eval(", "exec(", "compile(", "__import__(")
|
| 37 |
+
|
| 38 |
+
def grade(self, payload: Any) -> float:
|
| 39 |
+
text = _extract_text(payload)
|
| 40 |
+
if not text.strip():
|
| 41 |
+
return 0.20
|
| 42 |
+
lower = text.lower()
|
| 43 |
+
score = 0.20
|
| 44 |
+
if all(tok not in lower for tok in self._unsafe):
|
| 45 |
+
score += 0.45
|
| 46 |
+
if "def " in lower:
|
| 47 |
+
score += 0.25
|
| 48 |
+
return max(0.01, min(0.99, round(score, 2)))
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class HardGrader:
|
| 52 |
+
"""Hard: structure + typing signal."""
|
| 53 |
+
|
| 54 |
+
def grade(self, payload: Any) -> float:
|
| 55 |
+
text = _extract_text(payload)
|
| 56 |
+
if not text.strip():
|
| 57 |
+
return 0.30
|
| 58 |
+
try:
|
| 59 |
+
tree = ast.parse(text)
|
| 60 |
+
except SyntaxError:
|
| 61 |
+
return 0.25
|
| 62 |
+
|
| 63 |
+
score = 0.25
|
| 64 |
+
has_def_or_class = any(
|
| 65 |
+
isinstance(node, (ast.FunctionDef, ast.ClassDef)) for node in ast.walk(tree)
|
| 66 |
+
)
|
| 67 |
+
if has_def_or_class:
|
| 68 |
+
score += 0.30
|
| 69 |
+
|
| 70 |
+
has_annotations = False
|
| 71 |
+
for node in ast.walk(tree):
|
| 72 |
+
if isinstance(node, ast.AnnAssign):
|
| 73 |
+
has_annotations = True
|
| 74 |
+
break
|
| 75 |
+
if isinstance(node, ast.FunctionDef):
|
| 76 |
+
if node.returns is not None:
|
| 77 |
+
has_annotations = True
|
| 78 |
+
break
|
| 79 |
+
if any(arg.annotation is not None for arg in node.args.args):
|
| 80 |
+
has_annotations = True
|
| 81 |
+
break
|
| 82 |
+
if has_annotations:
|
| 83 |
+
score += 0.35
|
| 84 |
+
|
| 85 |
+
return max(0.01, min(0.99, round(score, 2)))
|
openenv.yaml
CHANGED
|
@@ -3,4 +3,17 @@ name: codeguard
|
|
| 3 |
type: space
|
| 4 |
runtime: fastapi
|
| 5 |
app: AgentBox.src.env:app
|
| 6 |
-
port: 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
type: space
|
| 4 |
runtime: fastapi
|
| 5 |
app: AgentBox.src.env:app
|
| 6 |
+
port: 7860
|
| 7 |
+
tasks:
|
| 8 |
+
- id: easy_task
|
| 9 |
+
name: Easy Task
|
| 10 |
+
difficulty: easy
|
| 11 |
+
grader: server.graders:EasyGrader
|
| 12 |
+
- id: medium_task
|
| 13 |
+
name: Medium Task
|
| 14 |
+
difficulty: medium
|
| 15 |
+
grader: server.graders:MediumGrader
|
| 16 |
+
- id: hard_task
|
| 17 |
+
name: Hard Task
|
| 18 |
+
difficulty: hard
|
| 19 |
+
grader: server.graders:HardGrader
|
server/graders.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from AgentBox.server.graders import EasyGrader, MediumGrader, HardGrader
|