Spaces:
Runtime error
Runtime error
Commit ·
692f802
1
Parent(s): cd5c208
fixes bugs and head ahead of winning
Browse filesFiles changed (16)
- __init__.py+2-2
- __pycache__/__init__.cpython-313.pyc
- __pycache__/client.cpython-313.pyc
- __pycache__/models.cpython-313.pyc
- client.py+1-1
- graders/bug_fix.py+2-2
- graders/dispatch.py+2-2
- graders/optimization.py+2-2
- graders/shared.py+2-2
- graders/syntax.py+2-2
- models/__init__.py+63-2
- openenv_models.pyDeleted-146
- server/__pycache__/app.cpython-313.pyc
- server/app.py+2-2
- server/env.py+2-2
- tests/test_scoring.py+1-1
12345678"""Public package exports for python_code_review_env."""from .client import PythonCodeReviewEnv, PythonEnvfrom .models import PyTorchCodeAnalyzerModelfrom .openenv_models import (PythonAction,PythonCodeReviewAction,PythonCodeReviewObservation,12345678"""Public package exports for python_code_review_env."""from .client import PythonCodeReviewEnv, PythonEnvfrom .models import (PyTorchCodeAnalyzerModel,PythonAction,PythonCodeReviewAction,PythonCodeReviewObservation,
6 unmodified lines789101112136 unmodified linesfrom openenv.core import EnvClientfrom openenv.core.client_types import StepResultfrom .openenv_models import (PythonCodeReviewAction,PythonCodeReviewObservation,PythonCodeReviewState,6 unmodified lines789101112136 unmodified linesfrom openenv.core import EnvClientfrom openenv.core.client_types import StepResultfrom .models import (PythonCodeReviewAction,PythonCodeReviewObservation,PythonCodeReviewState,
2 unmodified lines34567891011122 unmodified linesfrom __future__ import annotationstry:from ..openenv_models import TaskGradefrom ..tasks.catalog import ReviewTaskexcept ImportError:from openenv_models import TaskGradefrom tasks.catalog import ReviewTaskfrom .shared import (2 unmodified lines34567891011122 unmodified linesfrom __future__ import annotationstry:from ..models import TaskGradefrom ..tasks.catalog import ReviewTaskexcept ImportError:from models import TaskGradefrom tasks.catalog import ReviewTaskfrom .shared import (
2 unmodified lines34567891011122 unmodified linesfrom __future__ import annotationstry:from ..openenv_models import TaskGradefrom ..tasks.catalog import ReviewTaskexcept ImportError:from openenv_models import TaskGradefrom tasks.catalog import ReviewTaskfrom .bug_fix import grade_bug_fix_task2 unmodified lines34567891011122 unmodified linesfrom __future__ import annotationstry:from ..models import TaskGradefrom ..tasks.catalog import ReviewTaskexcept ImportError:from models import TaskGradefrom tasks.catalog import ReviewTaskfrom .bug_fix import grade_bug_fix_task
2 unmodified lines34567891011122 unmodified linesfrom __future__ import annotationstry:from ..openenv_models import TaskGradefrom ..tasks.catalog import ReviewTaskexcept ImportError:from openenv_models import TaskGradefrom tasks.catalog import ReviewTaskfrom .shared import (2 unmodified lines34567891011122 unmodified linesfrom __future__ import annotationstry:from ..models import TaskGradefrom ..tasks.catalog import ReviewTaskexcept ImportError:from models import TaskGradefrom tasks.catalog import ReviewTaskfrom .shared import (
11 unmodified lines1213141516171819202111 unmodified linesfrom typing import Any, Callable, Dict, Listtry:from ..openenv_models import TaskGradefrom ..tasks.catalog import CallCase, ReviewTaskexcept ImportError:from openenv_models import TaskGradefrom tasks.catalog import CallCase, ReviewTask11 unmodified lines1213141516171819202111 unmodified linesfrom typing import Any, Callable, Dict, Listtry:from ..models import TaskGradefrom ..tasks.catalog import CallCase, ReviewTaskexcept ImportError:from models import TaskGradefrom tasks.catalog import CallCase, ReviewTask
2 unmodified lines34567891011122 unmodified linesfrom __future__ import annotationstry:from ..openenv_models import TaskGradefrom ..tasks.catalog import ReviewTaskexcept ImportError:from openenv_models import TaskGradefrom tasks.catalog import ReviewTaskfrom .shared import (2 unmodified lines34567891011122 unmodified linesfrom __future__ import annotationstry:from ..models import TaskGradefrom ..tasks.catalog import ReviewTaskexcept ImportError:from models import TaskGradefrom tasks.catalog import ReviewTaskfrom .shared import (
12345"""PyTorch-backed model wrappers for the analyzer platform."""from .pytorch_model import PyTorchCodeAnalyzerModel__all__ = ["PyTorchCodeAnalyzerModel"]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566"""PyTorch-backed model wrappers plus OpenEnv schema exports."""from __future__ import annotationsimport importlib.utilimport sysfrom pathlib import Pathfrom .pytorch_model import PyTorchCodeAnalyzerModeldef _load_schema_module():schema_path = Path(__file__).resolve().parent.parent / "models.py"spec = importlib.util.spec_from_file_location("_python_env_schema_models", schema_path)if spec is None or spec.loader is None: # pragma: no coverraise ImportError(f"Unable to load schema models from {schema_path}")if spec.name in sys.modules:return sys.modules[spec.name]module = importlib.util.module_from_spec(spec)sys.modules[spec.name] = modulespec.loader.exec_module(module)for model_name in ("HistoryEntry","RewardDetails","PythonCodeReviewAction","PythonCodeReviewObservation","PythonCodeReviewState","TaskDescriptor","TaskSummary","TaskGrade","HealthResponse",):getattr(module, model_name).model_rebuild()return module_schema_models = _load_schema_module()HealthResponse = _schema_models.HealthResponseHistoryEntry = _schema_models.HistoryEntryPythonAction = _schema_models.PythonActionPythonCodeReviewAction = _schema_models.PythonCodeReviewActionPythonCodeReviewObservation = _schema_models.PythonCodeReviewObservationPythonCodeReviewState = _schema_models.PythonCodeReviewStatePythonObservation = _schema_models.PythonObservationPythonState = _schema_models.PythonStateRewardDetails = _schema_models.RewardDetailsTaskDescriptor = _schema_models.TaskDescriptorTaskGrade = _schema_models.TaskGradeTaskSummary = _schema_models.TaskSummary__all__ = ["HealthResponse","HistoryEntry","PyTorchCodeAnalyzerModel","PythonAction","PythonCodeReviewAction","PythonCodeReviewObservation","PythonCodeReviewState","PythonObservation","PythonState","RewardDetails","TaskDescriptor","TaskGrade","TaskSummary",]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146"""Typed models for the python_code_review_env environment."""
from __future__ import annotations
from typing import Any, Dict, List, Literal, Optional
from pydantic import BaseModel, Field
from openenv.core.env_server.types import Action, Observation, State
Difficulty = Literal["easy", "medium", "hard"]TaskKind = Literal["syntax_fix", "bug_fix", "optimization"]ActionType = Literal["analyze_code", "edit_code", "run_tests", "submit_solution"]
class HistoryEntry(BaseModel): """One environment transition recorded for the agent."""
step: int = Field(..., ge=0) action_type: ActionType status: str = Field(..., description="Short outcome summary.") reward: float = Field(..., gt=0.0, lt=1.0, description="Reward returned for the step.")
class RewardDetails(BaseModel): """Transparent reward decomposition for debugging and training."""
value: float = Field(..., gt=0.0, lt=1.0, description="Clamped net reward in (0.0, 1.0).") syntax_reward: float = Field(default=0.0) test_reward: float = Field(default=0.0) correctness_bonus: float = Field(default=0.0) quality_bonus: float = Field(default=0.0) error_reduction_bonus: float = Field(default=0.0) completion_bonus: float = Field(default=0.0) runtime_bonus: float = Field(default=0.0) progress_delta: float = Field(default=0.0) invalid_action_penalty: float = Field(default=0.0) timeout_penalty: float = Field(default=0.0) regression_penalty: float = Field(default=0.0) stagnation_penalty: float = Field(default=0.0) reason: str = Field(..., description="Human-readable reward explanation.") prev_score: float = Field(default=0.01, gt=0.0, lt=1.0) curr_score: float = Field(default=0.01, gt=0.0, lt=1.0) code_changed: bool = Field(default=False)
class PythonCodeReviewAction(Action): """Action schema exposed to the agent."""
action_type: ActionType = Field(..., description="Environment action to take.") code: Optional[str] = Field( default=None, description="Updated Python source for edit_code or submit_solution actions.", )
class PythonCodeReviewObservation(Observation): """Observation returned by reset and step."""
task_id: str = Field(..., description="Stable task identifier.") title: str = Field(..., description="Human-readable task title.") difficulty: Difficulty task_kind: TaskKind task_description: str = Field(..., description="Task instructions shown to the agent.") current_code: str = Field(..., description="Latest code under review.") errors: str = Field(default="", description="Syntax or execution errors.") test_results: str = Field(default="", description="Public test and benchmark feedback.") visible_tests: List[str] = Field(default_factory=list) history: List[HistoryEntry] = Field(default_factory=list) attempts_remaining: int = Field(..., ge=0) last_action_status: str = Field(default="") last_action_error: Optional[str] = Field(default=None) score: float = Field(..., gt=0.0, lt=1.0) reward: float = Field(default=0.1, gt=0.0, lt=1.0) done: bool = Field(default=False) reward_details: RewardDetails = Field( default_factory=lambda: RewardDetails(value=0.1, reason="Environment reset.") )
class PythonCodeReviewState(State): """Internal environment state exposed through /state."""
task_id: Optional[str] = Field(default=None) difficulty: Optional[Difficulty] = Field(default=None) task_kind: Optional[TaskKind] = Field(default=None) attempts_remaining: int = Field(default=0, ge=0) current_code: str = Field(default="") errors: str = Field(default="") test_results: str = Field(default="") history: List[HistoryEntry] = Field(default_factory=list) score: float = Field(default=0.01, gt=0.0, lt=1.0) done: bool = Field(default=False)
class TaskDescriptor(BaseModel): """Static task metadata."""
task_id: str title: str difficulty: Difficulty task_kind: TaskKind task_description: str starter_code: str visible_tests: List[str] = Field(default_factory=list) repo_summary: str = Field(default="") changed_files: List[str] = Field(default_factory=list) available_files: List[str] = Field(default_factory=list) goal: str = Field(default="") max_steps: int = Field(..., ge=1)
class TaskSummary(BaseModel): """Compact task listing entry."""
task_id: str difficulty: Difficulty title: str goal: str = Field(default="")
class TaskGrade(BaseModel): """Deterministic grader output."""
score: float = Field(..., gt=0.0, lt=1.0) syntax_score: float = Field(default=0.01, gt=0.0, lt=1.0) tests_passed: int = Field(default=0, ge=0) tests_total: int = Field(default=0, ge=0) quality_score: float = Field(default=0.01, gt=0.0, lt=1.0) runtime_score: float = Field(default=0.01, gt=0.0, lt=1.0) timed_out: bool = Field(default=False) details: Dict[str, Any] = Field(default_factory=dict)
class HealthResponse(BaseModel): """Health payload for smoke tests."""
status: Literal["ok"] = "ok" environment: str = "python_code_review_env" task_count: int = Field(default=0, ge=0)
PythonAction = PythonCodeReviewActionPythonObservation = PythonCodeReviewObservationPythonState = PythonCodeReviewState18 unmodified lines1920212223242526272818 unmodified linesgr = None # type: ignore[assignment]try:from ..openenv_models import PythonCodeReviewAction, PythonCodeReviewObservationfrom .env import PythonCodeReviewEnvironmentexcept ImportError:from openenv_models import PythonCodeReviewAction, PythonCodeReviewObservationfrom server.env import PythonCodeReviewEnvironment18 unmodified lines1920212223242526272818 unmodified linesgr = None # type: ignore[assignment]try:from ..models import PythonCodeReviewAction, PythonCodeReviewObservationfrom .env import PythonCodeReviewEnvironmentexcept ImportError:from models import PythonCodeReviewAction, PythonCodeReviewObservationfrom server.env import PythonCodeReviewEnvironment
10 unmodified lines111213141516175 unmodified lines2324252627282910 unmodified linestry:from ..graders import grade_taskfrom ..graders.shared import component_score, safe_ratio, strict_scorefrom ..openenv_models import (HistoryEntry,PythonCodeReviewAction,PythonCodeReviewObservation,5 unmodified linesexcept ImportError:from graders import grade_taskfrom graders.shared import component_score, safe_ratio, strict_scorefrom openenv_models import (HistoryEntry,PythonCodeReviewAction,PythonCodeReviewObservation,10 unmodified lines111213141516175 unmodified lines2324252627282910 unmodified linestry:from ..graders import grade_taskfrom ..graders.shared import component_score, safe_ratio, strict_scorefrom ..models import (HistoryEntry,PythonCodeReviewAction,PythonCodeReviewObservation,5 unmodified linesexcept ImportError:from graders import grade_taskfrom graders.shared import component_score, safe_ratio, strict_scorefrom models import (HistoryEntry,PythonCodeReviewAction,PythonCodeReviewObservation,
1234567from __future__ import annotationsfrom graders import grade_taskfrom openenv_models import PythonCodeReviewActionfrom server.env import PythonCodeReviewEnvironmentfrom tasks import list_tasks1234567from __future__ import annotationsfrom graders import grade_taskfrom models import PythonCodeReviewActionfrom server.env import PythonCodeReviewEnvironmentfrom tasks import list_tasks
__init__.py+2-2
__pycache__/__init__.cpython-313.pyc
__pycache__/client.cpython-313.pyc
__pycache__/models.cpython-313.pyc
client.py+1-1
graders/bug_fix.py+2-2
graders/dispatch.py+2-2
graders/optimization.py+2-2
graders/shared.py+2-2
graders/syntax.py+2-2
models/__init__.py+63-2
openenv_models.pyDeleted-146
server/__pycache__/app.cpython-313.pyc
server/app.py+2-2
server/env.py+2-2
tests/test_scoring.py+1-1