Spaces:
Sleeping
Sleeping
Ajjack4 commited on
Commit ·
ed395b6
1
Parent(s): 91a4057
guarantee [START]/[END] per task: wrap OpenAI() constructor, guard client=None
Browse files- inference.py +19 -3
inference.py
CHANGED
|
@@ -88,8 +88,11 @@ STRATEGY:
|
|
| 88 |
|
| 89 |
|
| 90 |
def get_model_message(
|
| 91 |
-
client: OpenAI, obs_text: str, history: List[dict]
|
| 92 |
) -> str:
|
|
|
|
|
|
|
|
|
|
| 93 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 94 |
messages.extend(history[-10:]) # keep last 10 turns to stay within context
|
| 95 |
messages.append({"role": "user", "content": obs_text})
|
|
@@ -234,11 +237,24 @@ async def run_task(client: OpenAI, env: EnvAdapter, task_id: str) -> None:
|
|
| 234 |
# ---------------------------------------------------------------------------
|
| 235 |
|
| 236 |
async def main() -> None:
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
env = EnvAdapter(ENV_BASE_URL)
|
| 239 |
|
| 240 |
for task_id in TASK_IDS:
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
|
| 244 |
if __name__ == "__main__":
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
def get_model_message(
|
| 91 |
+
client: Optional[OpenAI], obs_text: str, history: List[dict]
|
| 92 |
) -> str:
|
| 93 |
+
if client is None:
|
| 94 |
+
return '{"type": "submit"}'
|
| 95 |
+
|
| 96 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 97 |
messages.extend(history[-10:]) # keep last 10 turns to stay within context
|
| 98 |
messages.append({"role": "user", "content": obs_text})
|
|
|
|
| 237 |
# ---------------------------------------------------------------------------
|
| 238 |
|
| 239 |
async def main() -> None:
|
| 240 |
+
# Use placeholder key if none provided — real failure happens at API call
|
| 241 |
+
# level and is caught inside get_model_message(), not here.
|
| 242 |
+
api_key = HF_TOKEN if HF_TOKEN else "none"
|
| 243 |
+
try:
|
| 244 |
+
client = OpenAI(base_url=API_BASE_URL, api_key=api_key)
|
| 245 |
+
except Exception as exc:
|
| 246 |
+
print(f"[DEBUG] OpenAI client init failed: {exc}", flush=True)
|
| 247 |
+
client = None
|
| 248 |
+
|
| 249 |
env = EnvAdapter(ENV_BASE_URL)
|
| 250 |
|
| 251 |
for task_id in TASK_IDS:
|
| 252 |
+
# Wrap individually — one task failing must not prevent others logging.
|
| 253 |
+
try:
|
| 254 |
+
await run_task(client, env, task_id)
|
| 255 |
+
except Exception as exc:
|
| 256 |
+
print(f"[DEBUG] run_task({task_id}) uncaught: {exc}", flush=True)
|
| 257 |
+
print(f"[END] success=False steps=0 score=0.0 rewards=[]", flush=True)
|
| 258 |
|
| 259 |
|
| 260 |
if __name__ == "__main__":
|