96 lines
2.9 KiB
Python
96 lines
2.9 KiB
Python
import asyncio
|
|
import os
|
|
import sys
|
|
from dotenv import load_dotenv
|
|
|
|
if sys.stdout.encoding != 'utf-8':
|
|
try:
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
except Exception:
|
|
pass
|
|
|
|
load_dotenv()
|
|
|
|
async def diagnose_anthropic():
|
|
api_key = os.getenv("ANTHROPIC_API_KEY")
|
|
print("\n--- Testing Anthropic Models ---")
|
|
candidate_models = [
|
|
"claude-3-5-sonnet-latest",
|
|
"claude-3-5-haiku-latest",
|
|
"claude-3-haiku-20240307",
|
|
"claude-3-sonnet-20240229",
|
|
"claude-3-opus-20240229",
|
|
]
|
|
from anthropic import AsyncAnthropic
|
|
client = AsyncAnthropic(api_key=api_key)
|
|
for model in candidate_models:
|
|
try:
|
|
res = await client.messages.create(
|
|
model=model,
|
|
max_tokens=20,
|
|
messages=[{"role": "user", "content": "Hi"}],
|
|
)
|
|
print(f"[OK] Anthropic Model '{model}' WORKS! Response: {res.content[0].text.strip()}")
|
|
return model
|
|
except Exception as e:
|
|
print(f"[X] '{model}' failed: {e}")
|
|
return None
|
|
|
|
async def diagnose_gemini():
|
|
api_key = os.getenv("GEMINI_API_KEY")
|
|
print("\n--- Testing Gemini Models ---")
|
|
from google import genai
|
|
genai.configure(api_key=api_key)
|
|
try:
|
|
models = [m.name for m in genai.list_models() if 'generateContent' in m.supported_generation_methods]
|
|
print(f"Available Gemini models: {models[:10]}")
|
|
for m_name in models[:5]:
|
|
try:
|
|
m = genai.GenerativeModel(m_name)
|
|
res = await m.generate_content_async("Hi")
|
|
print(f"[OK] Gemini Model '{m_name}' WORKS! Response: {res.text.strip()}")
|
|
return m_name
|
|
except Exception as e:
|
|
print(f"[X] Gemini Model '{m_name}' failed: {e}")
|
|
except Exception as e:
|
|
print(f"[FAIL] Listing Gemini models failed: {e}")
|
|
return None
|
|
|
|
async def diagnose_sarvam():
|
|
api_key = os.getenv("SARVAM_API_KEY")
|
|
print("\n--- Testing Sarvam Speakers ---")
|
|
import httpx2
|
|
client = httpx2.AsyncClient(timeout=15.0)
|
|
headers = {
|
|
"api-subscription-key": api_key,
|
|
"Content-Type": "application/json",
|
|
}
|
|
payload = {
|
|
"inputs": ["வணக்கம்"],
|
|
"target_language_code": "ta-IN",
|
|
"speaker": "kavya",
|
|
"model": "bulbul:v1",
|
|
}
|
|
try:
|
|
res = await client.post(
|
|
"https://api.sarvam.ai/text-to-speech",
|
|
json=payload,
|
|
headers=headers,
|
|
)
|
|
if res.status_code == 200:
|
|
print("[OK] Sarvam TTS with speaker 'kavya' WORKS!")
|
|
return "kavya"
|
|
else:
|
|
print(f"[FAIL] Sarvam HTTP {res.status_code}: {res.text}")
|
|
except Exception as e:
|
|
print(f"[FAIL] Sarvam error: {e}")
|
|
return None
|
|
|
|
async def main():
|
|
await diagnose_anthropic()
|
|
await diagnose_gemini()
|
|
await diagnose_sarvam()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|