Spaces:
Sleeping
Sleeping
Commit ·
6d75c2b
1
Parent(s): df1e0f1
debugged the task validation error
Browse files- inference.py +11 -3
- openenv.yaml +35 -0
- pyproject.toml +2 -1
- requirements.txt +1 -0
- validate_submission.py +29 -0
inference.py
CHANGED
|
@@ -27,6 +27,14 @@ class TaskRun:
|
|
| 27 |
latency_s: float
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
class _TestResponse:
|
| 31 |
def __init__(self, status_code: int, payload: dict[str, Any]) -> None:
|
| 32 |
self.status_code = status_code
|
|
@@ -182,7 +190,7 @@ def _run_task(env_base_url: str, client: OpenAI | None, model_name: str, task_id
|
|
| 182 |
except Exception as exc:
|
| 183 |
return TaskRun(
|
| 184 |
task_id=task_id,
|
| 185 |
-
score=0.
|
| 186 |
rationale=f"reset_failed: {exc}",
|
| 187 |
latency_s=round(time.perf_counter() - t0, 3),
|
| 188 |
)
|
|
@@ -203,7 +211,7 @@ def _run_task(env_base_url: str, client: OpenAI | None, model_name: str, task_id
|
|
| 203 |
except Exception as exc:
|
| 204 |
return TaskRun(
|
| 205 |
task_id=task_id,
|
| 206 |
-
score=0.
|
| 207 |
rationale=f"step_failed: {exc}",
|
| 208 |
latency_s=round(time.perf_counter() - t0, 3),
|
| 209 |
)
|
|
@@ -263,7 +271,7 @@ def main() -> None:
|
|
| 263 |
|
| 264 |
avg_score = round(sum(item.score for item in results) / len(results), 4)
|
| 265 |
total_latency = round(sum(item.latency_s for item in results), 3)
|
| 266 |
-
status = "ok" if all(
|
| 267 |
|
| 268 |
_emit(
|
| 269 |
"END",
|
|
|
|
| 27 |
latency_s: float
|
| 28 |
|
| 29 |
|
| 30 |
+
def _task_run_succeeded(run: TaskRun) -> bool:
|
| 31 |
+
"""False when reset/step failed; scores stay in (0, 1) for platform validators."""
|
| 32 |
+
return not (
|
| 33 |
+
run.rationale.startswith("reset_failed:")
|
| 34 |
+
or run.rationale.startswith("step_failed:")
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
class _TestResponse:
|
| 39 |
def __init__(self, status_code: int, payload: dict[str, Any]) -> None:
|
| 40 |
self.status_code = status_code
|
|
|
|
| 190 |
except Exception as exc:
|
| 191 |
return TaskRun(
|
| 192 |
task_id=task_id,
|
| 193 |
+
score=0.01,
|
| 194 |
rationale=f"reset_failed: {exc}",
|
| 195 |
latency_s=round(time.perf_counter() - t0, 3),
|
| 196 |
)
|
|
|
|
| 211 |
except Exception as exc:
|
| 212 |
return TaskRun(
|
| 213 |
task_id=task_id,
|
| 214 |
+
score=0.01,
|
| 215 |
rationale=f"step_failed: {exc}",
|
| 216 |
latency_s=round(time.perf_counter() - t0, 3),
|
| 217 |
)
|
|
|
|
| 271 |
|
| 272 |
avg_score = round(sum(item.score for item in results) / len(results), 4)
|
| 273 |
total_latency = round(sum(item.latency_s for item in results), 3)
|
| 274 |
+
status = "ok" if results and all(_task_run_succeeded(r) for r in results) else "partial"
|
| 275 |
|
| 276 |
_emit(
|
| 277 |
"END",
|
openenv.yaml
CHANGED
|
@@ -4,3 +4,38 @@ type: space
|
|
| 4 |
runtime: fastapi
|
| 5 |
app: app.main:app
|
| 6 |
port: 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
runtime: fastapi
|
| 5 |
app: app.main:app
|
| 6 |
port: 7860
|
| 7 |
+
|
| 8 |
+
description: >
|
| 9 |
+
OpenEnv environment for deterministic AI code review evaluation across three tasks
|
| 10 |
+
(easy, medium, hard) with automated deterministic graders. Per-task scores are in (0, 1).
|
| 11 |
+
|
| 12 |
+
tasks:
|
| 13 |
+
- id: easy
|
| 14 |
+
name: Detect syntax errors
|
| 15 |
+
difficulty: easy
|
| 16 |
+
max_steps: 1
|
| 17 |
+
grader: true
|
| 18 |
+
score_range: [0.01, 0.99]
|
| 19 |
+
- id: medium
|
| 20 |
+
name: Suggest optimization
|
| 21 |
+
difficulty: medium
|
| 22 |
+
max_steps: 1
|
| 23 |
+
grader: true
|
| 24 |
+
score_range: [0.01, 0.99]
|
| 25 |
+
- id: hard
|
| 26 |
+
name: Full code review with scoring
|
| 27 |
+
difficulty: hard
|
| 28 |
+
max_steps: 1
|
| 29 |
+
grader: true
|
| 30 |
+
score_range: [0.01, 0.99]
|
| 31 |
+
|
| 32 |
+
grading:
|
| 33 |
+
type: automated
|
| 34 |
+
deterministic: true
|
| 35 |
+
graders:
|
| 36 |
+
- task_id: easy
|
| 37 |
+
type: deterministic
|
| 38 |
+
- task_id: medium
|
| 39 |
+
type: deterministic
|
| 40 |
+
- task_id: hard
|
| 41 |
+
type: deterministic
|
pyproject.toml
CHANGED
|
@@ -18,7 +18,8 @@ dependencies = [
|
|
| 18 |
"pydantic==2.11.7",
|
| 19 |
"openai==2.7.2",
|
| 20 |
"requests==2.32.3",
|
| 21 |
-
"openenv-core==0.2.3"
|
|
|
|
| 22 |
]
|
| 23 |
|
| 24 |
[project.scripts]
|
|
|
|
| 18 |
"pydantic==2.11.7",
|
| 19 |
"openai==2.7.2",
|
| 20 |
"requests==2.32.3",
|
| 21 |
+
"openenv-core==0.2.3",
|
| 22 |
+
"PyYAML>=6.0.1"
|
| 23 |
]
|
| 24 |
|
| 25 |
[project.scripts]
|
requirements.txt
CHANGED
|
@@ -4,3 +4,4 @@ pydantic==2.11.7
|
|
| 4 |
openai==2.7.2
|
| 5 |
requests==2.32.3
|
| 6 |
openenv-core==0.2.3
|
|
|
|
|
|
| 4 |
openai==2.7.2
|
| 5 |
requests==2.32.3
|
| 6 |
openenv-core==0.2.3
|
| 7 |
+
PyYAML>=6.0.1
|
validate_submission.py
CHANGED
|
@@ -20,6 +20,35 @@ def _check_openenv_yaml(path: Path) -> None:
|
|
| 20 |
if missing:
|
| 21 |
raise AssertionError(f"openenv.yaml missing keys: {missing}")
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def _check_api_contracts() -> None:
|
| 25 |
client = TestClient(app)
|
|
|
|
| 20 |
if missing:
|
| 21 |
raise AssertionError(f"openenv.yaml missing keys: {missing}")
|
| 22 |
|
| 23 |
+
try:
|
| 24 |
+
import yaml
|
| 25 |
+
except ImportError as exc: # pragma: no cover
|
| 26 |
+
raise AssertionError("PyYAML is required to validate openenv.yaml structure") from exc
|
| 27 |
+
|
| 28 |
+
data = yaml.safe_load(content)
|
| 29 |
+
if not isinstance(data, dict):
|
| 30 |
+
raise AssertionError("openenv.yaml must parse to a mapping")
|
| 31 |
+
|
| 32 |
+
tasks = data.get("tasks")
|
| 33 |
+
if not isinstance(tasks, list) or len(tasks) < 3:
|
| 34 |
+
raise AssertionError("openenv.yaml must include a tasks: list with at least 3 entries")
|
| 35 |
+
|
| 36 |
+
tasks_with_grader = sum(
|
| 37 |
+
1 for t in tasks if isinstance(t, dict) and t.get("grader") is True
|
| 38 |
+
)
|
| 39 |
+
grading = data.get("grading")
|
| 40 |
+
graders_list: list = []
|
| 41 |
+
if isinstance(grading, dict):
|
| 42 |
+
g = grading.get("graders")
|
| 43 |
+
if isinstance(g, list):
|
| 44 |
+
graders_list = g
|
| 45 |
+
|
| 46 |
+
if tasks_with_grader < 3 and len(graders_list) < 3:
|
| 47 |
+
raise AssertionError(
|
| 48 |
+
"openenv.yaml must declare graders for at least 3 tasks "
|
| 49 |
+
"(each task: grader: true, and/or grading.graders with 3+ entries)"
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
|
| 53 |
def _check_api_contracts() -> None:
|
| 54 |
client = TestClient(app)
|