Spaces:
Sleeping
Sleeping
databoysu commited on
Commit ·
9a026d7
1
Parent(s): f341e79
Thought enabling
Browse filesFiles changed (3)
18 unmodified lines1920212223242520 unmodified lines4647484950515258 unmodified lines11111211311411511611711811912012112212312412512612712812913013113213313413513632 unmodified lines16917017117217317417518 unmodified linesimport asyncioimport jsonimport osimport reimport sysfrom pathlib import Pathfrom typing import Any, Optional20 unmodified linesBENCHMARK = os.getenv("BENCHMARK", "tracefix_rl")MAX_STEPS = int(os.getenv("MAX_STEPS", "50"))SUCCESS_SCORE_THRESHOLD = float(os.getenv("SUCCESS_SCORE_THRESHOLD", "0.99"))THINKING_TOKEN_LIMIT = int(os.getenv("THINKING_TOKEN_LIMIT", "1000"))MAX_PARSE_RETRIES = 3SYSTEM_PROMPT = (58 unmodified linesdef _extract_json(text: str) -> dict[str, Any]:stripped = text.strip()try:return json.loads(stripped)except json.JSONDecodeError:passfence = re.search(r"```(?:json)?\s*({.*?})\s*```", stripped, re.DOTALL)if fence:try:return json.loads(fence.group(1))except json.JSONDecodeError:passblock = re.search(r"({.*?})", stripped, re.DOTALL)if block:try:return json.loads(block.group(1))except json.JSONDecodeError:passraise ValueError("Invalid JSON response.")def _build_observation_text(observation: Any) -> str:32 unmodified lines{"role": "user", "content": user_prompt},],"temperature": 0.0,"max_tokens": THINKING_TOKEN_LIMIT,"stream": False,}try:18 unmodified lines19202122232420 unmodified lines45464748495058 unmodified lines10911011111211311411511611711811912012112212332 unmodified lines15615715815916016118 unmodified linesimport asyncioimport jsonimport osimport sysfrom pathlib import Pathfrom typing import Any, Optional20 unmodified linesBENCHMARK = os.getenv("BENCHMARK", "tracefix_rl")MAX_STEPS = int(os.getenv("MAX_STEPS", "50"))SUCCESS_SCORE_THRESHOLD = float(os.getenv("SUCCESS_SCORE_THRESHOLD", "0.99"))MAX_PARSE_RETRIES = 3SYSTEM_PROMPT = (58 unmodified linesdef _extract_json(text: str) -> dict[str, Any]:stripped = text.strip()if stripped.startswith("```") and stripped.endswith("```"):first_newline = stripped.find("\n")if first_newline == -1:raise ValueError("Invalid JSON response.")stripped = stripped[first_newline + 1 : -3].strip()try:return json.loads(stripped)except json.JSONDecodeError as exc:raise ValueError("Invalid JSON response.") from excdef _build_observation_text(observation: Any) -> str:32 unmodified lines{"role": "user", "content": user_prompt},],"temperature": 0.0,"stream": False,}try:
4 unmodified lines5678910119 unmodified lines212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586874 unmodified linesfrom typing import Any, Dict, List, Literal, Optionalfrom openenv.core.env_server.types import Action, Observationfrom pydantic import BaseModel, Field, model_validatorActionType = Literal[9 unmodified linesclass CodeAction(Action):"""Structured action consumed by the environment."""thought: str = Field(...,description="Mandatory reasoning string before selecting an action.",)action_type: ActionType = Field(...,description="One of VIEW_CODE, RUN_TESTS, REPLACE_LINES, UNDO_EDIT, RESET_TO_ORIGINAL, SUBMIT.",)start_line: Optional[int] = Field(default=None)end_line: Optional[int] = Field(default=None)new_code_block: Optional[str] = Field(default=None)@model_validator(mode="before")@classmethoddef validate_and_normalize(cls, data: Any) -> Any:if not isinstance(data, dict):return dataaction_type = data.get("action_type")def _coerce_optional_int(value: Any) -> Optional[int]:if value is None:return Noneif isinstance(value, int):return valueif isinstance(value, str):raw = value.strip()if raw == "":return Nonetry:return int(raw)except ValueError:return Nonereturn Nonedata = dict(data)data["start_line"] = _coerce_optional_int(data.get("start_line"))data["end_line"] = _coerce_optional_int(data.get("end_line"))if action_type == "REPLACE_LINES":start_line = data.get("start_line")end_line = data.get("end_line")new_code_block = data.get("new_code_block")if start_line is None:raise ValueError("REPLACE_LINES requires start_line.")if end_line is None:raise ValueError("REPLACE_LINES requires end_line.")if new_code_block is None:raise ValueError("REPLACE_LINES requires new_code_block.")if start_line < 1 or end_line < 1:raise ValueError("REPLACE_LINES requires start_line and end_line >= 1.")if start_line > end_line:raise ValueError("REPLACE_LINES requires start_line <= end_line.")else:# Web UI often sends default line fields for non-edit actions.data["start_line"] = Nonedata["end_line"] = Nonedata["new_code_block"] = Nonereturn dataclass TestResult(BaseModel):4 unmodified lines5678910119 unmodified lines2122232425262728293031323334353637383940414243444546474849505152535455565758596061626364654 unmodified linesfrom typing import Any, Dict, List, Literal, Optionalfrom openenv.core.env_server.types import Action, Observationfrom pydantic import BaseModel, ConfigDict, FieldActionType = Literal[9 unmodified linesclass CodeAction(Action):"""Structured action consumed by the environment."""model_config = ConfigDict(strict=True)thought: str = Field(...,description=("MANDATORY. Analyze the localized_context and last_execution_output. ""If tests failed, identify the error line and root cause. Explicitly plan ""your next action before executing it."),)action_type: ActionType = Field(...,description=("The specific tool to use. VIEW_CODE to read. RUN_TESTS to execute and get ""tracebacks. REPLACE_LINES to apply a fix. UNDO_EDIT to revert your last ""change if it failed. SUBMIT only when all tests pass."),)start_line: Optional[int] = Field(default=None,description=("The inclusive start line number for REPLACE_LINES. You MUST use the exact ""integer keys provided in the code_dict observation."),)end_line: Optional[int] = Field(default=None,description=("The inclusive end line number for REPLACE_LINES. You MUST use the exact ""integer keys provided in the code_dict observation."),)new_code_block: Optional[str] = Field(default=None,description=("The exact replacement Python code. Must be properly indented to match the ""surrounding code. Do not include markdown formatting or backticks."),)class TestResult(BaseModel):
__pycache__/models.cpython-312.pyc
inference.py+7-21
models.py+34-56