Commit ·
63a4712
1
Parent(s): 4263caf
Optimize timeouts: 20s orchestrator, 15s LLM client, language-aware fallback
Browse files- app/core/llm_client.py +2 -1
- app/utils/guvi_handler.py +7 -5
- scripts/quick_test.py +6 -0
app/core/llm_client.py
CHANGED
|
@@ -49,7 +49,8 @@ from app.core.personas import PERSONAS
|
|
| 49 |
from app.core.time_utils import TimeAwareBehavior
|
| 50 |
|
| 51 |
# Shared HTTP Client for performance (Connection Pooling)
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
from enum import Enum
|
|
|
|
| 49 |
from app.core.time_utils import TimeAwareBehavior
|
| 50 |
|
| 51 |
# Shared HTTP Client for performance (Connection Pooling)
|
| 52 |
+
# Timeout reduced to 15s to fit within GUVI's 30s limit (with buffer for multiple calls)
|
| 53 |
+
_shared_client = httpx.AsyncClient(timeout=15.0)
|
| 54 |
|
| 55 |
|
| 56 |
from enum import Enum
|
app/utils/guvi_handler.py
CHANGED
|
@@ -237,8 +237,8 @@ class GUVIHandler:
|
|
| 237 |
|
| 238 |
logger.debug(f"🔥 Orchestrator reached with language: {request_language}") # [DEBUG] Verify flow
|
| 239 |
try:
|
| 240 |
-
# [LATENCY] Strict
|
| 241 |
-
#
|
| 242 |
result = await asyncio.wait_for(
|
| 243 |
orchestrator.process_message(
|
| 244 |
message=scammer_text,
|
|
@@ -250,16 +250,18 @@ class GUVIHandler:
|
|
| 250 |
should_finalize=is_finalizing_turn, # [RESTORED] Critical for callback trigger
|
| 251 |
request_language=request_language # [FIX] Pass GUVI language preference
|
| 252 |
),
|
| 253 |
-
timeout=
|
| 254 |
)
|
| 255 |
except asyncio.TimeoutError:
|
| 256 |
-
logger.error(f"DATA TIMEOUT ({session_id}): Orchestrator took >
|
| 257 |
# Construct a minimal valid 'result' to allow fall-through to standard response builder
|
|
|
|
|
|
|
| 258 |
result = {
|
| 259 |
"status": "partial_success",
|
| 260 |
"is_scam": False, # Fail open (continue)
|
| 261 |
"threat_level": "MEDIUM",
|
| 262 |
-
"honeypot_response": {"message":
|
| 263 |
"conversation": {"message_count": db_history_len + 1},
|
| 264 |
"aggregated_intelligence": conv.get("aggregated_intelligence", {}),
|
| 265 |
"confidence": 0.0,
|
|
|
|
| 237 |
|
| 238 |
logger.debug(f"🔥 Orchestrator reached with language: {request_language}") # [DEBUG] Verify flow
|
| 239 |
try:
|
| 240 |
+
# [LATENCY] Strict 20s Timeout to satisfy GUVI's 30s limit
|
| 241 |
+
# Buffer: 20s processing + 10s network/serialization headroom
|
| 242 |
result = await asyncio.wait_for(
|
| 243 |
orchestrator.process_message(
|
| 244 |
message=scammer_text,
|
|
|
|
| 250 |
should_finalize=is_finalizing_turn, # [RESTORED] Critical for callback trigger
|
| 251 |
request_language=request_language # [FIX] Pass GUVI language preference
|
| 252 |
),
|
| 253 |
+
timeout=20.0
|
| 254 |
)
|
| 255 |
except asyncio.TimeoutError:
|
| 256 |
+
logger.error(f"DATA TIMEOUT ({session_id}): Orchestrator took >20s. Forcing fallback.")
|
| 257 |
# Construct a minimal valid 'result' to allow fall-through to standard response builder
|
| 258 |
+
# Use language-aware fallback message
|
| 259 |
+
fallback_msg = "Hello? My network is slow, please wait..." if request_language == "english" else "Hello? Thoda network slow hai mera..."
|
| 260 |
result = {
|
| 261 |
"status": "partial_success",
|
| 262 |
"is_scam": False, # Fail open (continue)
|
| 263 |
"threat_level": "MEDIUM",
|
| 264 |
+
"honeypot_response": {"message": fallback_msg, "persona": "fallback"},
|
| 265 |
"conversation": {"message_count": db_history_len + 1},
|
| 266 |
"aggregated_intelligence": conv.get("aggregated_intelligence", {}),
|
| 267 |
"confidence": 0.0,
|
scripts/quick_test.py
CHANGED
|
@@ -42,6 +42,12 @@ def test_honeypot():
|
|
| 42 |
"sender": "scammer",
|
| 43 |
"text": test_message,
|
| 44 |
"timestamp": int(time.time() * 1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
|
|
|
| 42 |
"sender": "scammer",
|
| 43 |
"text": test_message,
|
| 44 |
"timestamp": int(time.time() * 1000)
|
| 45 |
+
},
|
| 46 |
+
"conversationHistory": [],
|
| 47 |
+
"metadata": {
|
| 48 |
+
"channel": "SMS",
|
| 49 |
+
"language": "English", # Request English responses
|
| 50 |
+
"locale": "IN"
|
| 51 |
}
|
| 52 |
}
|
| 53 |
|