Spaces:
Sleeping
Sleeping
Commit ·
bff2d46
1
Parent(s): 0d902c2
feat(inference): implement run_episode() — full reset→step loop with httpx client
Browse files- inference.py +22 -0
inference.py
CHANGED
|
@@ -39,3 +39,25 @@ def generate_attack(defender_response: str, turn: int, previous_success: float)
|
|
| 39 |
"intensity": min(0.3 + (turn * 0.1), 1.0),
|
| 40 |
"framing": framing,
|
| 41 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
"intensity": min(0.3 + (turn * 0.1), 1.0),
|
| 40 |
"framing": framing,
|
| 41 |
}
|
| 42 |
+
|
| 43 |
+
async def run_episode(task: str = "easy") -> dict:
|
| 44 |
+
import httpx
|
| 45 |
+
async with httpx.AsyncClient(base_url=API_BASE_URL, timeout=60.0) as http:
|
| 46 |
+
resp = await http.post("/reset")
|
| 47 |
+
reset_data = resp.json()
|
| 48 |
+
defender_resp = reset_data["observation"]["defender_response"]
|
| 49 |
+
prev_success = 0.0
|
| 50 |
+
|
| 51 |
+
turn = 0
|
| 52 |
+
while True:
|
| 53 |
+
turn += 1
|
| 54 |
+
action = generate_attack(defender_resp, turn, prev_success)
|
| 55 |
+
resp = await http.post("/step", json=action)
|
| 56 |
+
step_data = resp.json()
|
| 57 |
+
obs = step_data["observation"]
|
| 58 |
+
defender_resp = obs["defender_response"]
|
| 59 |
+
prev_success = obs["attack_success_estimate"]
|
| 60 |
+
if obs["episode_done"]: break
|
| 61 |
+
|
| 62 |
+
grade_resp = await http.post("/grade")
|
| 63 |
+
return {"task": task, "turns": turn, "grade": grade_resp.json()}
|