File size: 1,617 Bytes
bedfb0c |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#!/usr/bin/env python3
"""Quick test of Space API"""
import httpx
import sys
SPACE_URL = "https://jeanbaptdzd-open-finance-llm-8b.hf.space"
try:
# Test root endpoint
r = httpx.get(f"{SPACE_URL}/", timeout=10)
if r.status_code == 200:
data = r.json()
print(f"β Root endpoint: {data.get('backend', 'unknown')}")
print(f" Model: {data.get('model', 'unknown')}")
else:
print(f"β Root endpoint failed: {r.status_code}")
sys.exit(1)
# Test models endpoint
r = httpx.get(f"{SPACE_URL}/v1/models", timeout=10)
if r.status_code == 200:
data = r.json()
models = data.get('data', [])
print(f"β Models endpoint: {len(models)} model(s)")
else:
print(f"β Models endpoint failed: {r.status_code}")
sys.exit(1)
# Test chat completion (short)
r = httpx.post(
f"{SPACE_URL}/v1/chat/completions",
json={
"model": "DragonLLM/qwen3-8b-fin-v1.0",
"messages": [{"role": "user", "content": "Say hello"}],
"max_tokens": 50
},
timeout=60
)
if r.status_code == 200:
data = r.json()
content = data['choices'][0]['message']['content']
print(f"β Chat completion: {len(content)} chars")
print(f" Preview: {content[:50]}...")
else:
print(f"β Chat completion failed: {r.status_code}")
print(f" Response: {r.text[:200]}")
sys.exit(1)
print("\nβ All tests passed! Space is working.")
except Exception as e:
print(f"β Error: {e}")
sys.exit(1)
|