Spaces:
Sleeping
Sleeping
File size: 1,071 Bytes
02c0b36 | 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 | #!/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}")
|