import asyncio import re import json import os import sys # Add app to path sys.path.append(os.path.dirname(os.path.abspath(__file__))) from app.utils.extractors import extract_all from app.core.model_registry import model_registry from app.core.groq_errors import GROQ_LIMITS from app.core.llm_client import llm_client, ModelRole async def verify_system(): print("\nšŸš€ SENTINEL COMPREHENSIVE VERIFICATION") print("=======================================\n") # 1. Verify Regex Extraction (Whitelist Fix) print("[1] Testing Regex Extraction (UPI & Phone)") test_text = "Please verify immediately! Send ₹1 to scammer.fraud@fakebank or call +91-9876543210. Also try payer@okicici." print(f" Input: '{test_text}'") intel = extract_all(test_text) upi_passed = "scammer.fraud@fakebank" in intel["upi_ids"] phone_passed = "+919876543210" in intel["phone_numbers"] if upi_passed and phone_passed: print(" āœ… REGEX CHECK: PASSED (Found whitelist domain & phone)") else: print(f" āŒ REGEX CHECK: FAILED. Got: {intel}") # 2. Verify Rate Limit Registry (Compound Fix) print("\n[2] Testing Rate Limit Registry (Compound TPD)") compound_meta = model_registry.MODELS.get("groq/compound", {}) limit_meta = GROQ_LIMITS.get("groq/compound", {}) tpd_reg = compound_meta.get("tpd", 0) tpd_err = limit_meta.get("tpd", 0) if tpd_reg >= 1_000_000_000 and tpd_err >= 1_000_000_000: print(f" āœ… REGISTRY CHECK: PASSED (TPD is Unlimited: {tpd_reg})") else: print(f" āŒ REGISTRY CHECK: FAILED. TPD: {tpd_reg}") # 3. Verify LLM Client (400 Loop Fix) print("\n[3] Testing LLM Client Connectivity & Structure") try: # We simulate a "Structured" call which was failing with 400 schema = { "type": "object", "properties": { "risk_score": {"type": "number"}, "analysis": {"type": "string"}, "tags": {"type": "array", "items": {"type": "string"}} }, "required": ["risk_score", "analysis"] } # Use FAST_CHAT to stay cheap, but force STRUCTURED role to test logic # Actually we need to test the logic that was failing. # The switchboard might route to llama-3.3-70b-versatile for STRUCTURED. # We trust the switchboard. response = await llm_client.generate_structured( prompt="Analyze this message: 'I need money urgent'. Return risk score 0-1.", schema=schema, role=ModelRole.STRUCTURED_OUTPUT ) if response.content: try: data = json.loads(response.content) print(f" āœ… LLM STRUCTURAL CHECK: PASSED") print(f" output: {str(data)[:100]}...") except: print(f" āš ļø LLM CHECK: Valid response but JSON parse failed (Static Fallback?). Content: {response.content[:50]}...") else: print(" āŒ LLM CHECK: FAILED (Empty Response)") except Exception as e: print(f" āŒ LLM CHECK: CRASHED with error: {e}") if __name__ == "__main__": asyncio.run(verify_system())