Download api/test_api.py from dispatchAI/dispatchAI-API: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/dispatchAI/dispatchAI-API/resolve/main/api/test_api.py
- Command line
-
hf download hf://dispatchAI/dispatchAI-API/api/test_api.py
-
curl -L -o test_api.py https://huggingface.co/dispatchAI/dispatchAI-API/resolve/main/api/test_api.py
1.48 kB
| import httpx, asyncio, json | |
| async def test(): | |
| # Test gateway health | |
| async with httpx.AsyncClient(timeout=10.0) as c: | |
| r = await c.get('http://127.0.0.1:8081/') | |
| print(f'Gateway: {r.status_code}') | |
| # Test phone proxy health | |
| async with httpx.AsyncClient(timeout=10.0) as c: | |
| r = await c.get('http://127.0.0.1:5000/health') | |
| print(f'Phone proxy: {r.status_code} - {r.text}') | |
| # Test full chat | |
| print('\nTesting chat...') | |
| async with httpx.AsyncClient(timeout=120.0) as c: | |
| r = await c.post( | |
| 'http://127.0.0.1:8081/v1/chat/completions', | |
| headers={ | |
| 'Content-Type': 'application/json', | |
| 'Authorization': 'Bearer da-demo-key-0001' | |
| }, | |
| json={ | |
| 'model': 'dispatchAI/SmolLM2-135M-Instruct-mobile', | |
| 'messages': [{'role': 'user', 'content': 'What is the capital of France?'}], | |
| 'max_tokens': 20 | |
| } | |
| ) | |
| print(f'Chat status: {r.status_code}') | |
| try: | |
| data = json.loads(r.text) | |
| content = data.get('choices', [{}])[0].get('message', {}).get('content', '') | |
| phone = data.get('phone_info', {}) | |
| usage = data.get('usage', {}) | |
| print(f'Content: "{content[:200]}"') | |
| print(f'Phone: {phone}') | |
| print(f'Usage: {usage}') | |
| except: | |
| print(f'Raw: {r.text[:500]}') | |
| asyncio.run(test()) | |