| 154 | # Proxy helpers # |
| 155 | # ------------------------------------------------------------------ # |
| 156 | async def wait_for_proxy(timeout_s=90): |
| 157 | url = f"http://127.0.0.1:{PROXY_PORT}/docs" |
| 158 | start = time.monotonic() |
| 159 | while True: |
| 160 | try: |
| 161 | async with httpx.AsyncClient(timeout=3.0) as client: |
| 162 | resp = await client.get(url) |
| 163 | if resp.status_code < 500: |
| 164 | return |
| 165 | except Exception: |
| 166 | pass |
| 167 | if time.monotonic() - start > timeout_s: |
| 168 | raise TimeoutError("Proxy did not start in time") |
| 169 | await asyncio.sleep(1.0) |
| 170 | |
| 171 | |
| 172 | async def send_chat(messages, session_id, session_done=False, retries=3): |