Spaces:
Sleeping
Sleeping
Commit ·
90c162a
1
Parent(s): d250f99
feat: enhance TaskRunResponse with raw_total_reward and normalized score calculation
Browse files
code-review-env/server/app.py
CHANGED
|
@@ -64,7 +64,9 @@ class TaskRunResponse(BaseModel):
|
|
| 64 |
|
| 65 |
episode_id: str
|
| 66 |
total_steps: int
|
|
|
|
| 67 |
total_reward: float
|
|
|
|
| 68 |
modules_total: int
|
| 69 |
modules_completed: int
|
| 70 |
done: bool
|
|
@@ -224,6 +226,18 @@ UI_INDEX_PATH = Path(__file__).resolve().parent / "static" / "index.html"
|
|
| 224 |
STATIC_ROOT = Path(__file__).resolve().parent / "static"
|
| 225 |
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
def _default_source_root() -> str:
|
| 228 |
configured = os.getenv("GRAPHREVIEW_SOURCE_ROOT", "sample_project")
|
| 229 |
return str(Path(configured).resolve())
|
|
@@ -544,10 +558,13 @@ def run_task(task_id: str, payload: TaskRunRequest) -> TaskRunResponse:
|
|
| 544 |
if done:
|
| 545 |
break
|
| 546 |
|
|
|
|
| 547 |
return TaskRunResponse(
|
| 548 |
episode_id=episode_id,
|
| 549 |
total_steps=total_steps,
|
| 550 |
-
|
|
|
|
|
|
|
| 551 |
modules_total=modules_total,
|
| 552 |
modules_completed=len(completed_modules),
|
| 553 |
done=done,
|
|
|
|
| 64 |
|
| 65 |
episode_id: str
|
| 66 |
total_steps: int
|
| 67 |
+
raw_total_reward: float
|
| 68 |
total_reward: float
|
| 69 |
+
score: float
|
| 70 |
modules_total: int
|
| 71 |
modules_completed: int
|
| 72 |
done: bool
|
|
|
|
| 226 |
STATIC_ROOT = Path(__file__).resolve().parent / "static"
|
| 227 |
|
| 228 |
|
| 229 |
+
def _strict_score_from_reward(total_reward: float, total_steps: int) -> float:
|
| 230 |
+
# Map average per-step reward to (0, 1) and avoid exact endpoints required by validator.
|
| 231 |
+
eps = 1e-6
|
| 232 |
+
avg_reward = total_reward / max(total_steps, 1)
|
| 233 |
+
score = (avg_reward + 1.0) / 2.0
|
| 234 |
+
if score <= eps:
|
| 235 |
+
return eps
|
| 236 |
+
if score >= 1.0 - eps:
|
| 237 |
+
return 1.0 - eps
|
| 238 |
+
return score
|
| 239 |
+
|
| 240 |
+
|
| 241 |
def _default_source_root() -> str:
|
| 242 |
configured = os.getenv("GRAPHREVIEW_SOURCE_ROOT", "sample_project")
|
| 243 |
return str(Path(configured).resolve())
|
|
|
|
| 558 |
if done:
|
| 559 |
break
|
| 560 |
|
| 561 |
+
normalized_score = _strict_score_from_reward(total_reward=total_reward, total_steps=total_steps)
|
| 562 |
return TaskRunResponse(
|
| 563 |
episode_id=episode_id,
|
| 564 |
total_steps=total_steps,
|
| 565 |
+
raw_total_reward=total_reward,
|
| 566 |
+
total_reward=normalized_score,
|
| 567 |
+
score=normalized_score,
|
| 568 |
modules_total=modules_total,
|
| 569 |
modules_completed=len(completed_modules),
|
| 570 |
done=done,
|