File size: 1,478 Bytes
a0ca2ba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 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())
|