Spaces:
Sleeping
Sleeping
Subhash Vadaparthi commited on
Commit Β·
9f9f225
1
Parent(s): f9069ec
fix: comply with OpenEnv rules - single START/END, real-time STEP, no score field
Browse files202 unmodified lines2032042052062072082092102112122132142155 unmodified lines22122222322422522622722822923023123223323423523623723823914 unmodified lines254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303202 unmodified lines# ββ Main inference loop βββββββββββββββββββββββββββββββββββββββββββββdef run_inference():# Task definitionstask_defs = [{"name": "book_appointment", "grader": "grade_task_1"},{"name": "scheduling_conflicts", "grader": "grade_task_2"},{"name": "priority_scheduling", "grader": "grade_task_3"},]env = HealthcareEnvironment(seed=42)obs = env.reset()5 unmodified lines"current_step": obs.current_step,}# ββ Grading functions for the final [END] line ββgrader = TaskGrader(env)# ββ Reporting Setup ββ# Using the primary task name as the default reporterprimary_task = "healthcare_appointment_scheduling"try:# ββ Run the agent loop ββsteps_taken = 0rewards: List[float] = []action_history: List[Dict[str, Any]] = []while not env.done and steps_taken < MAX_STEPS:action_dict = get_action_from_llm(obs_dict, action_history)14 unmodified lines"current_step": obs.current_step,}step_error = obs.info.get("error") if obs.info else "null"steps_taken += 1rewards.append(obs.reward)# Track history for playback in the task blocksaction_history.append({"action_str": action_to_str(action_dict),"reward": obs.reward,"error": step_error if step_error != "null" else None,})# ββ Emit one structured [START]/[STEP]/[END] block per task ββfor task_def in task_defs:task_name = task_def["name"]grade_fn = getattr(grader, task_def["grader"])task_score = grade_fn() # Get score strictly in (0, 1) from tasks.pysuccess = task_score > 0.5log_start(task=task_name, env=BENCHMARK, model=MODEL_NAME)# Re-emit steps for each task (playback)for i in range(len(rewards)):# We need to reconstruct the STEP output for each task# Using the stored historyh = action_history[i]log_step(step=i + 1,action=h["action_str"],reward=h["reward"],done=(i == len(rewards) - 1), # Last step is doneerror=h["error"] if h["error"] else "null",)# Emit [END] with explicit scorerewards_str = ",".join(f"{r:.2f}" for r in rewards)print(f"[END] success={str(success).lower()} steps={steps_taken} score={task_score:.2f} rewards={rewards_str}",flush=True,)except Exception:# Fallback to ensure [END] is emitted even on failurelog_end(success=False, steps=steps_taken if 'steps_taken' in locals() else 0, rewards=rewards if 'rewards' in locals() else [0.0])finally:sys.exit(0)202 unmodified lines2032042052062072085 unmodified lines21421521621721821922022122222322422522622722814 unmodified lines243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280202 unmodified lines# ββ Main inference loop βββββββββββββββββββββββββββββββββββββββββββββdef run_inference():env = HealthcareEnvironment(seed=42)obs = env.reset()5 unmodified lines"current_step": obs.current_step,}steps_taken = 0rewards: List[float] = []action_history: List[Dict[str, Any]] = []try:# ββ Single [START] ββlog_start(task="healthcare_task", env=BENCHMARK, model=MODEL_NAME)# ββ Agent loop: each [STEP] emitted once, immediately after env.step() ββwhile not env.done and steps_taken < MAX_STEPS:action_dict = get_action_from_llm(obs_dict, action_history)14 unmodified lines"current_step": obs.current_step,}step_error = obs.info.get("error") if obs.info and obs.info.get("error") else "null"steps_taken += 1rewards.append(obs.reward)# Emit [STEP] ONCE, immediately after env.step()log_step(step=steps_taken,action=action_to_str(action_dict),reward=obs.reward,done=env.done,error=step_error,)# Track history for LLM contextaction_history.append({"action_str": action_to_str(action_dict),"reward": obs.reward,"error": step_error if step_error != "null" else None,})# ββ Determine success ββgrader = TaskGrader(env)task_score = grader.grade_task_1()success = task_score > 0.5# ββ Single [END] ββlog_end(success=success, steps=steps_taken, rewards=rewards)except Exception:# Fallback to ensure [END] is emitted even on failurelog_end(success=False, steps=steps_taken, rewards=rewards if rewards else [0.0])finally:sys.exit(0)
inference.py+26-49