dispatchAI-API / api /test_api.py
3morixd's picture
Upload api/test_api.py with huggingface_hub
a0ca2ba verified
Raw
History Blame Contribute Delete
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())