Spaces:
Runtime error
Runtime error
| 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()) | |