Spaces:
Sleeping
Sleeping
Download tests/test_end_to_end.py from fallingbody/Fallnet: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/fallingbody/Fallnet/resolve/main/tests/test_end_to_end.py
- Command line
-
hf download hf://spaces/fallingbody/Fallnet/tests/test_end_to_end.py
-
curl -L -o test_end_to_end.py https://huggingface.co/spaces/fallingbody/Fallnet/resolve/main/tests/test_end_to_end.py
1.04 kB
| import asyncio | |
| import httpx | |
| import websockets | |
| import json | |
| async def main(): | |
| async with websockets.connect("ws://127.0.0.1:8000/ws") as ws: | |
| async with httpx.AsyncClient(timeout=120.0) as client: | |
| resp = await client.post("http://127.0.0.1:8000/api/trigger", json={"prompt": "What is 2 + 2?"}) | |
| print("Trigger response status:", resp.status_code) | |
| full_tokens = [] | |
| while True: | |
| try: | |
| msg = await asyncio.wait_for(ws.recv(), timeout=5.0) | |
| data = json.loads(msg) | |
| if data.get("type") == "token": | |
| t = data.get("token", "") | |
| full_tokens.append(t) | |
| print(t, end="", flush=True) | |
| elif data.get("type") == "log" and "completed" in data.get("msg", "").lower(): | |
| break | |
| except asyncio.TimeoutError: | |
| break | |
| print(f"\n\nFull Result: '{''.join(full_tokens)}'") | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |