Spaces:
Sleeping
Sleeping
File size: 2,246 Bytes
f361447 | 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | import os
from dotenv import load_dotenv
load_dotenv()
GREEN = '\033[92m'
RED = '\033[91m'
RESET = '\033[0m'
def test_gemini():
try:
from google import genai
client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY"))
response = client.models.generate_content(
model="gemini-2.0-flash",
contents="Say hello in one word"
)
print(f"{GREEN}[OK] Gemini: {response.text.strip()}{RESET}")
return True
except Exception as e:
print(f"{RED}[FAIL] Gemini failed: {e}{RESET}")
return False
def test_groq():
try:
import groq
client = groq.Groq(api_key=os.environ.get("GROQ_API_KEY"))
r = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=[{"role":"user","content":"Say hello in one word"}],
max_tokens=10
)
print(f"{GREEN}[OK] Groq: {r.choices[0].message.content.strip()}{RESET}")
return True
except Exception as e:
print(f"{RED}[FAIL] Groq failed: {e}{RESET}")
return False
def test_openrouter():
try:
import requests
r = requests.post(
"https://openrouter.ai/api/v1/chat/completions",
headers={
"Authorization": f"Bearer {os.environ.get('OPENROUTER_API_KEY')}",
"Content-Type": "application/json"
},
json={
"model": "mistralai/mistral-7b-instruct:free",
"messages": [{"role":"user","content":"Say hello in one word"}]
},
timeout=30
)
text = r.json()["choices"][0]["message"]["content"].strip()
print(f"{GREEN}[OK] OpenRouter: {text}{RESET}")
return True
except Exception as e:
print(f"{RED}[FAIL] OpenRouter failed: {e}{RESET}")
return False
print("Testing all APIs...\n")
g = test_gemini()
gr = test_groq()
op = test_openrouter()
print("\n--- SUMMARY ---")
if gr or op:
print(f"{GREEN}[OK] Enough APIs working to proceed!{RESET}")
if not g:
print(f"WARN: Gemini hit daily limit — Groq/OpenRouter will be primary")
else:
print(f"{RED}[FAIL] No APIs working — check your .env keys{RESET}")
|