Spaces:
Running
Running
Commit Β·
b4f20cf
1
Parent(s): 09576c0
Fix log formatting to exactly match diagnostic feedback
Browse files- inference.py +16 -15
inference.py
CHANGED
|
@@ -214,17 +214,19 @@ def run_task(client: OpenAI, task_id: str) -> float:
|
|
| 214 |
resp = requests.post(f"{ENV_URL}/reset", json={"task_id": task_id}, timeout=30)
|
| 215 |
data = resp.json()
|
| 216 |
|
|
|
|
| 217 |
if "error" in data and not data.get("episode_id"):
|
| 218 |
# ββ MANDATORY: [START] line even on error ββ
|
| 219 |
-
|
| 220 |
-
print(f"[
|
|
|
|
| 221 |
return 0.0
|
| 222 |
|
| 223 |
-
episode_id = data.get("episode_id", "
|
| 224 |
obs = data.get("observation", data)
|
| 225 |
|
| 226 |
# ββ MANDATORY [START] β exact spec format ββ
|
| 227 |
-
print(f"[START]
|
| 228 |
|
| 229 |
rewards = []
|
| 230 |
history = []
|
|
@@ -260,7 +262,7 @@ def run_task(client: OpenAI, task_id: str) -> float:
|
|
| 260 |
except Exception as e:
|
| 261 |
error_msg = str(e)
|
| 262 |
# ββ MANDATORY [STEP] line on connection error ββ
|
| 263 |
-
print(f"[STEP] step={step_num} action={action_type} reward=0.
|
| 264 |
rewards.append(0.0)
|
| 265 |
break
|
| 266 |
|
|
@@ -279,21 +281,18 @@ def run_task(client: OpenAI, task_id: str) -> float:
|
|
| 279 |
display_action = "invalid"
|
| 280 |
|
| 281 |
# ββ MANDATORY [STEP] β exact spec format ββ
|
| 282 |
-
|
| 283 |
-
print(f"[STEP] step={step_num} action={display_action} reward={reward:.2f} done={str(done).lower()} error={error_val}", flush=True)
|
| 284 |
|
| 285 |
if done:
|
| 286 |
break
|
| 287 |
|
| 288 |
-
#
|
| 289 |
-
|
| 290 |
-
success = score > 0.0
|
| 291 |
-
rewards_str = ",".join(f"{r:.2f}" for r in rewards)
|
| 292 |
|
| 293 |
# ββ MANDATORY [END] β exact spec format ββ
|
| 294 |
-
print(f"[END]
|
| 295 |
|
| 296 |
-
return
|
| 297 |
|
| 298 |
|
| 299 |
def main() -> None:
|
|
@@ -318,8 +317,10 @@ def main() -> None:
|
|
| 318 |
try:
|
| 319 |
scores[task_id] = run_task(client, task_id)
|
| 320 |
except Exception as e:
|
| 321 |
-
|
| 322 |
-
|
|
|
|
|
|
|
| 323 |
scores[task_id] = 0.0
|
| 324 |
|
| 325 |
avg = round(sum(scores.values()) / max(len(scores), 1), 2)
|
|
|
|
| 214 |
resp = requests.post(f"{ENV_URL}/reset", json={"task_id": task_id}, timeout=30)
|
| 215 |
data = resp.json()
|
| 216 |
|
| 217 |
+
import uuid
|
| 218 |
if "error" in data and not data.get("episode_id"):
|
| 219 |
# ββ MANDATORY: [START] line even on error ββ
|
| 220 |
+
episode_id = f"ep-{uuid.uuid4().hex[:8]}"
|
| 221 |
+
print(f"[START] task_id={task_id} episode_id={episode_id}", flush=True)
|
| 222 |
+
print(f"[END] task_id={task_id} episode_id={episode_id} total_reward=0.0000 steps=0", flush=True)
|
| 223 |
return 0.0
|
| 224 |
|
| 225 |
+
episode_id = data.get("episode_id", f"ep-{uuid.uuid4().hex[:8]}")
|
| 226 |
obs = data.get("observation", data)
|
| 227 |
|
| 228 |
# ββ MANDATORY [START] β exact spec format ββ
|
| 229 |
+
print(f"[START] task_id={task_id} episode_id={episode_id}", flush=True)
|
| 230 |
|
| 231 |
rewards = []
|
| 232 |
history = []
|
|
|
|
| 262 |
except Exception as e:
|
| 263 |
error_msg = str(e)
|
| 264 |
# ββ MANDATORY [STEP] line on connection error ββ
|
| 265 |
+
print(f"[STEP] task_id={task_id} step={step_num} action={action_type} reward=0.0000 done=True", flush=True)
|
| 266 |
rewards.append(0.0)
|
| 267 |
break
|
| 268 |
|
|
|
|
| 281 |
display_action = "invalid"
|
| 282 |
|
| 283 |
# ββ MANDATORY [STEP] β exact spec format ββ
|
| 284 |
+
print(f"[STEP] task_id={task_id} step={step_num} action={display_action} reward={reward:.4f} done={done}", flush=True)
|
|
|
|
| 285 |
|
| 286 |
if done:
|
| 287 |
break
|
| 288 |
|
| 289 |
+
# Sum the rewards for multi-turn accumulation
|
| 290 |
+
total_reward = sum(rewards) if rewards else 0.0
|
|
|
|
|
|
|
| 291 |
|
| 292 |
# ββ MANDATORY [END] β exact spec format ββ
|
| 293 |
+
print(f"[END] task_id={task_id} episode_id={episode_id} total_reward={total_reward:.4f} steps={step_num}", flush=True)
|
| 294 |
|
| 295 |
+
return total_reward
|
| 296 |
|
| 297 |
|
| 298 |
def main() -> None:
|
|
|
|
| 317 |
try:
|
| 318 |
scores[task_id] = run_task(client, task_id)
|
| 319 |
except Exception as e:
|
| 320 |
+
import uuid
|
| 321 |
+
episode_id = f"ep-{uuid.uuid4().hex[:8]}"
|
| 322 |
+
print(f"[START] task_id={task_id} episode_id={episode_id}", flush=True)
|
| 323 |
+
print(f"[END] task_id={task_id} episode_id={episode_id} total_reward=0.0000 steps=0", flush=True)
|
| 324 |
scores[task_id] = 0.0
|
| 325 |
|
| 326 |
avg = round(sum(scores.values()) / max(len(scores), 1), 2)
|