Spaces:
Sleeping
Sleeping
- inference.py +24 -9
inference.py
CHANGED
|
@@ -17,7 +17,7 @@ except ImportError:
|
|
| 17 |
|
| 18 |
API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
|
| 19 |
MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
|
| 20 |
-
|
| 21 |
LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME")
|
| 22 |
OPENENV_BASE_URL = os.getenv("OPENENV_BASE_URL")
|
| 23 |
TASK_NAME = os.getenv("TASK_NAME", "engineer-manager")
|
|
@@ -176,9 +176,18 @@ def choose_fallback_action(observation: dict[str, Any]) -> dict[str, int]:
|
|
| 176 |
current_slot = int(observation.get("current_slot", 0))
|
| 177 |
distraction_risk = float(observation.get("distraction_risk", 0.0))
|
| 178 |
mute_comms = bool(observation.get("mute_comms", False))
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
| 180 |
return {"target_slot": current_slot, "operation": 3}
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
empty_slot = first_future_slot(observation, 0)
|
| 183 |
if empty_slot is not None and observation.get("task_buffer"):
|
| 184 |
return {"target_slot": empty_slot, "operation": 1}
|
|
@@ -237,7 +246,10 @@ async def create_env() -> Any:
|
|
| 237 |
return env
|
| 238 |
|
| 239 |
if LOCAL_IMAGE_NAME:
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
env = _InProcessEnvClient()
|
| 243 |
await env.connect()
|
|
@@ -252,23 +264,25 @@ async def main() -> None:
|
|
| 252 |
success = False
|
| 253 |
score = 0.0
|
| 254 |
observation: dict[str, Any] = {}
|
|
|
|
| 255 |
|
| 256 |
log_start(TASK_NAME, BENCHMARK, MODEL_NAME)
|
| 257 |
|
| 258 |
try:
|
| 259 |
-
if
|
| 260 |
-
raise RuntimeError("Missing required environment variable: HF_TOKEN")
|
| 261 |
-
|
| 262 |
-
client = OpenAI(base_url=API_BASE_URL, api_key=HF_TOKEN)
|
| 263 |
env = await create_env()
|
| 264 |
result = await env.reset()
|
| 265 |
observation = dict(result.observation)
|
| 266 |
|
| 267 |
for step in range(1, MAX_STEPS + 1):
|
| 268 |
if result.done:
|
|
|
|
| 269 |
break
|
| 270 |
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
| 272 |
action_text = _action_to_text(action)
|
| 273 |
step_error: str | None = None
|
| 274 |
|
|
@@ -292,10 +306,11 @@ async def main() -> None:
|
|
| 292 |
)
|
| 293 |
|
| 294 |
if done:
|
|
|
|
| 295 |
break
|
| 296 |
|
| 297 |
score = round(normalize_score(math.fsum(rewards), observation), 2)
|
| 298 |
-
success = score > 0.0
|
| 299 |
except Exception:
|
| 300 |
success = False
|
| 301 |
score = 0.0
|
|
|
|
| 17 |
|
| 18 |
API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
|
| 19 |
MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
|
| 20 |
+
API_KEY = os.getenv("HF_TOKEN") or os.getenv("API_KEY")
|
| 21 |
LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME")
|
| 22 |
OPENENV_BASE_URL = os.getenv("OPENENV_BASE_URL")
|
| 23 |
TASK_NAME = os.getenv("TASK_NAME", "engineer-manager")
|
|
|
|
| 176 |
current_slot = int(observation.get("current_slot", 0))
|
| 177 |
distraction_risk = float(observation.get("distraction_risk", 0.0))
|
| 178 |
mute_comms = bool(observation.get("mute_comms", False))
|
| 179 |
+
recovery_state = int(observation.get("recovery_state", 0))
|
| 180 |
+
timeline = observation.get("timeline") or []
|
| 181 |
+
|
| 182 |
+
if current_slot == 0 and distraction_risk > 0.0 and not mute_comms:
|
| 183 |
return {"target_slot": current_slot, "operation": 3}
|
| 184 |
|
| 185 |
+
if recovery_state > 0:
|
| 186 |
+
return {"target_slot": current_slot, "operation": 0}
|
| 187 |
+
|
| 188 |
+
if current_slot < len(timeline) and int(timeline[current_slot]) == 0 and observation.get("task_buffer"):
|
| 189 |
+
return {"target_slot": current_slot, "operation": 1}
|
| 190 |
+
|
| 191 |
empty_slot = first_future_slot(observation, 0)
|
| 192 |
if empty_slot is not None and observation.get("task_buffer"):
|
| 193 |
return {"target_slot": empty_slot, "operation": 1}
|
|
|
|
| 246 |
return env
|
| 247 |
|
| 248 |
if LOCAL_IMAGE_NAME:
|
| 249 |
+
try:
|
| 250 |
+
return await GenericEnvClient.from_docker_image(LOCAL_IMAGE_NAME)
|
| 251 |
+
except Exception:
|
| 252 |
+
pass
|
| 253 |
|
| 254 |
env = _InProcessEnvClient()
|
| 255 |
await env.connect()
|
|
|
|
| 264 |
success = False
|
| 265 |
score = 0.0
|
| 266 |
observation: dict[str, Any] = {}
|
| 267 |
+
completed = False
|
| 268 |
|
| 269 |
log_start(TASK_NAME, BENCHMARK, MODEL_NAME)
|
| 270 |
|
| 271 |
try:
|
| 272 |
+
client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY) if API_KEY else None
|
|
|
|
|
|
|
|
|
|
| 273 |
env = await create_env()
|
| 274 |
result = await env.reset()
|
| 275 |
observation = dict(result.observation)
|
| 276 |
|
| 277 |
for step in range(1, MAX_STEPS + 1):
|
| 278 |
if result.done:
|
| 279 |
+
completed = True
|
| 280 |
break
|
| 281 |
|
| 282 |
+
if client is None:
|
| 283 |
+
action = choose_fallback_action(observation)
|
| 284 |
+
else:
|
| 285 |
+
action = get_model_action(client, step, observation, rewards, history)
|
| 286 |
action_text = _action_to_text(action)
|
| 287 |
step_error: str | None = None
|
| 288 |
|
|
|
|
| 306 |
)
|
| 307 |
|
| 308 |
if done:
|
| 309 |
+
completed = True
|
| 310 |
break
|
| 311 |
|
| 312 |
score = round(normalize_score(math.fsum(rewards), observation), 2)
|
| 313 |
+
success = completed and score >= 0.0
|
| 314 |
except Exception:
|
| 315 |
success = False
|
| 316 |
score = 0.0
|