Download test_local_api.py from cong182/firstAI: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/cong182/firstAI/resolve/db8cd85abd6bedbbcf5f3f371400a8f749ff3d93/test_local_api.py
- Command line
-
hf download hf://spaces/cong182/firstAI@db8cd85abd6bedbbcf5f3f371400a8f749ff3d93/test_local_api.py
-
curl -L -o test_local_api.py https://huggingface.co/spaces/cong182/firstAI/resolve/db8cd85abd6bedbbcf5f3f371400a8f749ff3d93/test_local_api.py
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}") | |