firstAI / test_local_api.py
ndc8
update
3239c69
raw
history blame
1.34 kB
#!/usr/bin/env python3
"""
Test script for local API endpoint
"""
import requests
import json
# Local API endpoint
API_URL = "http://localhost:8000/v1/chat/completions"
# Test payload with the correct model name
payload = {
"model": "unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, what can you do?"}
],
"max_tokens": 64,
"temperature": 0.7
}
print("πŸ§ͺ Testing Local API...")
print(f"πŸ“‘ URL: {API_URL}")
print(f"πŸ“¦ Payload: {json.dumps(payload, indent=2)}")
print("-" * 50)
try:
response = requests.post(API_URL, json=payload, timeout=30)
print(f"βœ… Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"πŸ€– Response: {json.dumps(result, indent=2)}")
if 'choices' in result and len(result['choices']) > 0:
print(f"πŸ’¬ AI Message: {result['choices'][0]['message']['content']}")
else:
print(f"❌ Error: {response.text}")
except requests.exceptions.ConnectionError:
print("❌ Connection failed - make sure the server is running locally")
except requests.exceptions.Timeout:
print("⏰ Request timed out")
except Exception as e:
print(f"❌ Error: {e}")