Upload api/test_api.py with huggingface_hub
Browse files- api/test_api.py +41 -0
api/test_api.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import httpx, asyncio, json
|
| 2 |
+
|
| 3 |
+
async def test():
|
| 4 |
+
# Test gateway health
|
| 5 |
+
async with httpx.AsyncClient(timeout=10.0) as c:
|
| 6 |
+
r = await c.get('http://127.0.0.1:8081/')
|
| 7 |
+
print(f'Gateway: {r.status_code}')
|
| 8 |
+
|
| 9 |
+
# Test phone proxy health
|
| 10 |
+
async with httpx.AsyncClient(timeout=10.0) as c:
|
| 11 |
+
r = await c.get('http://127.0.0.1:5000/health')
|
| 12 |
+
print(f'Phone proxy: {r.status_code} - {r.text}')
|
| 13 |
+
|
| 14 |
+
# Test full chat
|
| 15 |
+
print('\nTesting chat...')
|
| 16 |
+
async with httpx.AsyncClient(timeout=120.0) as c:
|
| 17 |
+
r = await c.post(
|
| 18 |
+
'http://127.0.0.1:8081/v1/chat/completions',
|
| 19 |
+
headers={
|
| 20 |
+
'Content-Type': 'application/json',
|
| 21 |
+
'Authorization': 'Bearer da-demo-key-0001'
|
| 22 |
+
},
|
| 23 |
+
json={
|
| 24 |
+
'model': 'dispatchAI/SmolLM2-135M-Instruct-mobile',
|
| 25 |
+
'messages': [{'role': 'user', 'content': 'What is the capital of France?'}],
|
| 26 |
+
'max_tokens': 20
|
| 27 |
+
}
|
| 28 |
+
)
|
| 29 |
+
print(f'Chat status: {r.status_code}')
|
| 30 |
+
try:
|
| 31 |
+
data = json.loads(r.text)
|
| 32 |
+
content = data.get('choices', [{}])[0].get('message', {}).get('content', '')
|
| 33 |
+
phone = data.get('phone_info', {})
|
| 34 |
+
usage = data.get('usage', {})
|
| 35 |
+
print(f'Content: "{content[:200]}"')
|
| 36 |
+
print(f'Phone: {phone}')
|
| 37 |
+
print(f'Usage: {usage}')
|
| 38 |
+
except:
|
| 39 |
+
print(f'Raw: {r.text[:500]}')
|
| 40 |
+
|
| 41 |
+
asyncio.run(test())
|