resolving inference
Browse files- inference.py +11 -4
inference.py
CHANGED
|
@@ -227,7 +227,7 @@ def get_model_action(client: OpenAI, step: int, obs, last_reward: float, history
|
|
| 227 |
text = (completion.choices[0].message.content or "").strip()
|
| 228 |
return get_action_from_text(obs.phase, text)
|
| 229 |
except Exception as exc:
|
| 230 |
-
print(f"[DEBUG] Model request failed: {exc}", flush=True)
|
| 231 |
# Fallback actions
|
| 232 |
if obs.phase == "market":
|
| 233 |
return JewelryAction(market_action="buy", gold_qty=1.0), "buy 1.0"
|
|
@@ -293,7 +293,8 @@ async def run_episode(client: OpenAI, task_name: str, env_name: str, base_url: s
|
|
| 293 |
try:
|
| 294 |
await env.close()
|
| 295 |
except Exception as e:
|
| 296 |
-
|
|
|
|
| 297 |
log_end(success=success, steps=steps_taken, score=score, rewards=rewards)
|
| 298 |
|
| 299 |
return score
|
|
@@ -309,8 +310,14 @@ TASKS = [
|
|
| 309 |
|
| 310 |
async def main() -> None:
|
| 311 |
client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
|
| 312 |
-
#
|
| 313 |
-
base_url = os.getenv("ENV_BASE_URL"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
for task in TASKS:
|
| 316 |
await run_episode(client, task["id"], task["env"], base_url)
|
|
|
|
| 227 |
text = (completion.choices[0].message.content or "").strip()
|
| 228 |
return get_action_from_text(obs.phase, text)
|
| 229 |
except Exception as exc:
|
| 230 |
+
# print(f"[DEBUG] Model request failed: {exc}", flush=True)
|
| 231 |
# Fallback actions
|
| 232 |
if obs.phase == "market":
|
| 233 |
return JewelryAction(market_action="buy", gold_qty=1.0), "buy 1.0"
|
|
|
|
| 293 |
try:
|
| 294 |
await env.close()
|
| 295 |
except Exception as e:
|
| 296 |
+
pass
|
| 297 |
+
# print(f"[DEBUG] env.close() error: {e}", flush=True)
|
| 298 |
log_end(success=success, steps=steps_taken, score=score, rewards=rewards)
|
| 299 |
|
| 300 |
return score
|
|
|
|
| 310 |
|
| 311 |
async def main() -> None:
|
| 312 |
client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
|
| 313 |
+
# Resolve server URL: evaluator env var → IMAGE_NAME → HF Space → localhost
|
| 314 |
+
base_url = os.getenv("ENV_BASE_URL")
|
| 315 |
+
if not base_url and IMAGE_NAME:
|
| 316 |
+
# Evaluator sets IMAGE_NAME; derive the Space URL
|
| 317 |
+
base_url = f"https://{IMAGE_NAME.replace('/', '-').replace('_', '-')}.hf.space"
|
| 318 |
+
if not base_url:
|
| 319 |
+
base_url = os.getenv("SPACE_URL", "http://localhost:8000")
|
| 320 |
+
print(f"[CONFIG] base_url={base_url}", flush=True)
|
| 321 |
|
| 322 |
for task in TASKS:
|
| 323 |
await run_episode(client, task["id"], task["env"], base_url)
|