feat: complete production hardening implementation, specialty canonicalization, google-genai migration, voice reliability, sqlite concurrency, and test suite consolidation
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
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 test_openai():
|
||||
api_key = os.getenv("OPENAI_API_KEY")
|
||||
model = os.getenv("OPENAI_MODEL", "gpt-4o-mini")
|
||||
print(f"\n--- [1/4] Testing OpenAI ({model}) ---")
|
||||
if not api_key:
|
||||
print("[FAIL] OPENAI_API_KEY is not set.")
|
||||
return False, "Key missing"
|
||||
try:
|
||||
from openai import AsyncOpenAI
|
||||
client = AsyncOpenAI(api_key=api_key)
|
||||
response = await client.chat.completions.create(
|
||||
model=model,
|
||||
messages=[{"role": "user", "content": "Respond with JSON: {\"status\": \"ok\"}"}],
|
||||
response_format={"type": "json_object"},
|
||||
max_completion_tokens=50,
|
||||
)
|
||||
content = response.choices[0].message.content
|
||||
print(f"[OK] OpenAI Success: {content.strip()}")
|
||||
return True, "Connected & Working"
|
||||
except Exception as e:
|
||||
err_msg = str(e)
|
||||
print(f"[FAIL] OpenAI Error: {err_msg}")
|
||||
return False, err_msg
|
||||
|
||||
async def test_anthropic():
|
||||
api_key = os.getenv("ANTHROPIC_API_KEY")
|
||||
model = os.getenv("ANTHROPIC_MODEL", "claude-sonnet-4-5-20250929")
|
||||
print(f"\n--- [2/4] Testing Anthropic Claude ({model}) ---")
|
||||
if not api_key:
|
||||
print("[FAIL] ANTHROPIC_API_KEY is not set.")
|
||||
return False, "Key missing"
|
||||
try:
|
||||
from anthropic import AsyncAnthropic
|
||||
client = AsyncAnthropic(api_key=api_key)
|
||||
response = await client.messages.create(
|
||||
model=model,
|
||||
max_tokens=50,
|
||||
messages=[{"role": "user", "content": "Reply with 'ok'"}],
|
||||
)
|
||||
content = response.content[0].text
|
||||
print(f"[OK] Claude Success: {content.strip()}")
|
||||
return True, "Connected & Working"
|
||||
except Exception as e:
|
||||
err_msg = str(e)
|
||||
print(f"[FAIL] Claude Error: {err_msg}")
|
||||
return False, err_msg
|
||||
|
||||
async def test_gemini():
|
||||
api_key = os.getenv("GEMINI_API_KEY")
|
||||
model_name = os.getenv("GEMINI_MODEL", "gemini-3.6-flash")
|
||||
print(f"\n--- [3/4] Testing Google Gemini ({model_name}) ---")
|
||||
if not api_key:
|
||||
print("[FAIL] GEMINI_API_KEY is not set.")
|
||||
return False, "Key missing"
|
||||
try:
|
||||
from google import genai
|
||||
genai.configure(api_key=api_key)
|
||||
model = genai.GenerativeModel(model_name)
|
||||
response = await model.generate_content_async("Say 'ok'")
|
||||
print(f"[OK] Gemini Success: {response.text.strip()}")
|
||||
return True, "Connected & Working"
|
||||
except Exception as e:
|
||||
err_msg = str(e)
|
||||
print(f"[FAIL] Gemini Error: {err_msg}")
|
||||
return False, err_msg
|
||||
|
||||
async def test_sarvam():
|
||||
api_key = os.getenv("SARVAM_API_KEY")
|
||||
print(f"\n--- [4/4] Testing Sarvam AI (TTS bulbul:v2) ---")
|
||||
if not api_key:
|
||||
print("[FAIL] SARVAM_API_KEY is not set.")
|
||||
return False, "Key missing"
|
||||
try:
|
||||
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": "anushka",
|
||||
"model": "bulbul:v2",
|
||||
}
|
||||
res = await client.post(
|
||||
"https://api.sarvam.ai/text-to-speech",
|
||||
json=payload,
|
||||
headers=headers,
|
||||
)
|
||||
if res.status_code == 200:
|
||||
audios = res.json().get("audios", [])
|
||||
print(f"[OK] Sarvam AI Success: Generated {len(audios)} audio stream(s)")
|
||||
return True, "Connected & Working"
|
||||
else:
|
||||
err_msg = f"HTTP {res.status_code}: {res.text}"
|
||||
print(f"[FAIL] Sarvam AI Error: {err_msg}")
|
||||
return False, err_msg
|
||||
except Exception as e:
|
||||
err_msg = str(e)
|
||||
print(f"[FAIL] Sarvam AI Error: {err_msg}")
|
||||
return False, err_msg
|
||||
|
||||
async def main():
|
||||
print("========================================")
|
||||
print("AI Patient Onboarding - Key Verification")
|
||||
print("========================================")
|
||||
results = {}
|
||||
results["OpenAI"] = await test_openai()
|
||||
results["Anthropic Claude"] = await test_anthropic()
|
||||
results["Google Gemini"] = await test_gemini()
|
||||
results["Sarvam AI"] = await test_sarvam()
|
||||
|
||||
print("\n========================================")
|
||||
print("SUMMARY")
|
||||
print("========================================")
|
||||
for provider, (passed, msg) in results.items():
|
||||
tag = "[PASS]" if passed else "[FAIL]"
|
||||
print(f"{tag} {provider}: {msg}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user