Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """Quick test of HuggingFace API connectivity.""" | |
| import os | |
| from openai import OpenAI | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| if not HF_TOKEN: | |
| raise ValueError("HF_TOKEN required") | |
| # Test different endpoints | |
| endpoints = [ | |
| ("router-v1", "https://router.huggingface.co/v1", "Qwen/Qwen2.5-7B-Instruct"), | |
| ("router-direct", "https://router.huggingface.co", "Qwen/Qwen2.5-7B-Instruct"), | |
| ] | |
| for name, base_url, model in endpoints: | |
| try: | |
| print(f"\nTesting {name} ({base_url})...") | |
| client = OpenAI(base_url=base_url, api_key=HF_TOKEN) | |
| response = client.chat.completions.create( | |
| model=model, | |
| messages=[ | |
| {"role": "user", "content": "What is 2+2? Answer in 1 word."} | |
| ], | |
| max_tokens=10, | |
| temperature=0.1, | |
| ) | |
| print(f"✓ {name} works!") | |
| print(f" Response: {response.choices[0].message.content}") | |
| break | |
| except Exception as e: | |
| error_msg = str(e)[:150] | |
| print(f"✗ {name} failed: {error_msg}") | |