Spaces:
Sleeping
Sleeping
Commit ·
8ab3fe3
1
Parent(s): 48ab79c
Fix NoneType subscript bug in json parser pipeline
Browse files- code-review-env/inference.py +19 -13
code-review-env/inference.py
CHANGED
|
@@ -216,7 +216,7 @@ _CATEGORY_MAP = {
|
|
| 216 |
def normalize_action(raw: Dict[str, Any]) -> Dict[str, Any]:
|
| 217 |
"""Map alternate LLM JSON (action_type, comment, …) to env CodeReviewAction shape."""
|
| 218 |
|
| 219 |
-
if not isinstance(raw, dict):
|
| 220 |
return {"operation": "done"}
|
| 221 |
|
| 222 |
op = raw.get("operation")
|
|
@@ -526,7 +526,7 @@ def _fallback_action_for_task(task_id: str, found_keys: set[str]) -> Dict[str, A
|
|
| 526 |
def _sanitize_and_finalize_action(action: Dict[str, Any], observation: Dict[str, Any], task_id: str) -> Dict[str, Any]:
|
| 527 |
"""Validate/repair an action using the observation, to maximize grader alignment."""
|
| 528 |
|
| 529 |
-
if not isinstance(action, dict):
|
| 530 |
return {"operation": "done"}
|
| 531 |
|
| 532 |
op = action.get("operation")
|
|
@@ -617,7 +617,10 @@ def _call_env_step(client: httpx.Client, base_url: str, action: Dict[str, Any])
|
|
| 617 |
|
| 618 |
r = client.post(f"{base_url}/step", json=action, timeout=30.0)
|
| 619 |
r.raise_for_status()
|
| 620 |
-
|
|
|
|
|
|
|
|
|
|
| 621 |
|
| 622 |
|
| 623 |
def _llm_next_action(
|
|
@@ -680,9 +683,10 @@ def run_task(task_id: str, *, env_base_url: str, api_base_url: str, model_name:
|
|
| 680 |
if time.time() - start_t > float(timeout_s):
|
| 681 |
action = {"operation": "done"}
|
| 682 |
result = _call_env_step(http, env_base_url, action)
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
|
|
|
| 686 |
score = float(info.get("current_score", score))
|
| 687 |
rewards.append(reward)
|
| 688 |
steps_taken = step
|
|
@@ -693,9 +697,10 @@ def run_task(task_id: str, *, env_base_url: str, api_base_url: str, model_name:
|
|
| 693 |
if required_keys and required_keys.issubset(found_keys):
|
| 694 |
action = {"operation": "done"}
|
| 695 |
result = _call_env_step(http, env_base_url, action)
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
|
|
|
| 699 |
score = float(info.get("current_score", score))
|
| 700 |
rewards.append(reward)
|
| 701 |
steps_taken = step
|
|
@@ -737,10 +742,11 @@ def run_task(task_id: str, *, env_base_url: str, api_base_url: str, model_name:
|
|
| 737 |
found_keys.add(k)
|
| 738 |
|
| 739 |
result = _call_env_step(http, env_base_url, action)
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
|
|
|
| 744 |
score = float(info.get("current_score", score))
|
| 745 |
|
| 746 |
rewards.append(reward)
|
|
|
|
| 216 |
def normalize_action(raw: Dict[str, Any]) -> Dict[str, Any]:
|
| 217 |
"""Map alternate LLM JSON (action_type, comment, …) to env CodeReviewAction shape."""
|
| 218 |
|
| 219 |
+
if raw is None or not isinstance(raw, dict):
|
| 220 |
return {"operation": "done"}
|
| 221 |
|
| 222 |
op = raw.get("operation")
|
|
|
|
| 526 |
def _sanitize_and_finalize_action(action: Dict[str, Any], observation: Dict[str, Any], task_id: str) -> Dict[str, Any]:
|
| 527 |
"""Validate/repair an action using the observation, to maximize grader alignment."""
|
| 528 |
|
| 529 |
+
if action is None or not isinstance(action, dict):
|
| 530 |
return {"operation": "done"}
|
| 531 |
|
| 532 |
op = action.get("operation")
|
|
|
|
| 617 |
|
| 618 |
r = client.post(f"{base_url}/step", json=action, timeout=30.0)
|
| 619 |
r.raise_for_status()
|
| 620 |
+
res = r.json()
|
| 621 |
+
if res is None:
|
| 622 |
+
return {"observation": {}, "reward": 0.0, "done": True, "info": {"error": "NoneType JSON returned"}}
|
| 623 |
+
return res
|
| 624 |
|
| 625 |
|
| 626 |
def _llm_next_action(
|
|
|
|
| 683 |
if time.time() - start_t > float(timeout_s):
|
| 684 |
action = {"operation": "done"}
|
| 685 |
result = _call_env_step(http, env_base_url, action)
|
| 686 |
+
if result is None: result = {}
|
| 687 |
+
reward = float(result.get("reward", 0.0))
|
| 688 |
+
done = bool(result.get("done", True))
|
| 689 |
+
info = result.get("info", {})
|
| 690 |
score = float(info.get("current_score", score))
|
| 691 |
rewards.append(reward)
|
| 692 |
steps_taken = step
|
|
|
|
| 697 |
if required_keys and required_keys.issubset(found_keys):
|
| 698 |
action = {"operation": "done"}
|
| 699 |
result = _call_env_step(http, env_base_url, action)
|
| 700 |
+
if result is None: result = {}
|
| 701 |
+
reward = float(result.get("reward", 0.0))
|
| 702 |
+
done = bool(result.get("done", True))
|
| 703 |
+
info = result.get("info", {})
|
| 704 |
score = float(info.get("current_score", score))
|
| 705 |
rewards.append(reward)
|
| 706 |
steps_taken = step
|
|
|
|
| 742 |
found_keys.add(k)
|
| 743 |
|
| 744 |
result = _call_env_step(http, env_base_url, action)
|
| 745 |
+
if result is None: result = {}
|
| 746 |
+
obs = result.get("observation", {})
|
| 747 |
+
reward = float(result.get("reward", 0.0))
|
| 748 |
+
done = bool(result.get("done", True))
|
| 749 |
+
info = result.get("info", {})
|
| 750 |
score = float(info.get("current_score", score))
|
| 751 |
|
| 752 |
rewards.append(reward)
|