customeragent-api / verify_fallback.py
anasraza526's picture
Clean deploy to Hugging Face
ac90985
import asyncio
import os
import sys
# Add server directory to path
sys.path.append('/Users/mac/Projects/customerAgent/server')
from app.services.llm_service import get_llm_service
from app.services.gemini_service import get_gemini_service
async def test_fallback():
print("πŸš€ Initializing Fallback Test...")
llm = get_llm_service()
gemini = get_gemini_service()
# Force Gemini to fail by breaking the API key
original_key = gemini.api_key
gemini.api_key = "INVALID_KEY"
gemini.enabled = True # Keep it enabled so it tries to call and fails
print(f"πŸ“‘ Primary: Gemini (API Key sabotaged)")
print(f"πŸ“‘ Fallback ready: {'Yes' if llm.local_llm else 'No'}")
try:
print("⏳ Generating via fallback (this may take time on CPU)...")
response = await llm.generate_response(
prompt="What is the capital of France?",
system_prompt="Be concise.",
context={"website_id": 19, "industry": "general"}
)
print(f"🏁 Final Response: {response}")
finally:
# Restore API key
gemini.api_key = original_key
if __name__ == "__main__":
asyncio.run(test_fallback())