From cc78711e17ba1075faff963e0d4a728d5ef79ab4 Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Sat, 28 Mar 2026 06:08:43 +0100 Subject: [PATCH] fix(nordagpt): smart router complexity for long queries + show routing info in badge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Long messages (>150 chars) with 2+ categories → complex (was medium) - Badge shows actual model used, complexity icon, thinking level - Done chunk includes complexity, thinking, routed_by metadata Co-Authored-By: Claude Opus 4.6 (1M context) --- nordabiz_chat.py | 5 ++++- smart_router.py | 13 ++++++++----- templates/chat.html | 12 ++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/nordabiz_chat.py b/nordabiz_chat.py index 1d7d750..ddbbb82 100644 --- a/nordabiz_chat.py +++ b/nordabiz_chat.py @@ -1689,7 +1689,10 @@ W dyskusji [Artur Wiertel](link) pytał o moderację. Pełna treść: [moje uwag 'latency_ms': latency_ms, 'model': actual_model, 'cost_usd': round(cost_usd, 6), - 'full_text': full_response_text + 'full_text': full_response_text, + 'complexity': route_decision.get('complexity', '?'), + 'thinking': route_decision.get('thinking', '?'), + 'routed_by': route_decision.get('routed_by', '?'), } except Exception as e: diff --git a/smart_router.py b/smart_router.py index 6f85634..ce1f136 100644 --- a/smart_router.py +++ b/smart_router.py @@ -141,13 +141,16 @@ def route_query_fast(message: str, user_context: dict) -> Optional[dict]: logger.debug("fast_router: no confident match, deferring to AI router") return None - # Determine complexity by number of matched categories - if len(matched_categories) == 1: - complexity = 'medium' - elif len(matched_categories) <= 3: + # Determine complexity by number of matched categories + message length + is_long = len(message) > 150 + multi_question = any(w in msg for w in ['jak ', 'jakie ', 'w jaki sposób', 'kto mógł']) + + if len(matched_categories) >= 3 or (len(matched_categories) >= 2 and is_long): + complexity = 'complex' + elif len(matched_categories) >= 2 or is_long or multi_question: complexity = 'medium' else: - complexity = 'complex' + complexity = 'simple' if len(message) < 80 else 'medium' logger.debug( "fast_router: matched categories=%s complexity=%s", diff --git a/templates/chat.html b/templates/chat.html index 6d4b081..d3fe2c6 100755 --- a/templates/chat.html +++ b/templates/chat.html @@ -2514,12 +2514,20 @@ async function sendMessage() { const modelLabels = { 'flash': '⚡ Flash', 'pro': '🧠 Pro', 'gemini-3-flash-preview': '⚡ Flash', + 'gemini-3.1-flash-lite-preview': '⚡ Lite', 'gemini-3.1-pro-preview': '🧠 Pro' }; - const modelLabel = modelLabels[currentModel] || currentModel; + const actualModel = chunk.model || currentModel; + const modelLabel = modelLabels[actualModel] || modelLabels[currentModel] || actualModel; const latencySec = ((chunk.latency_ms || 0) / 1000).toFixed(1); const costStr = (chunk.cost_usd || 0) > 0 ? `$${(chunk.cost_usd).toFixed(4)}` : '$0.00'; - let badgeHTML = `${modelLabel} · ${latencySec}s · ${costStr}`; + const complexityIcons = {'simple': '💬', 'medium': '🔍', 'complex': '🧠'}; + const thinkingLabels = {'minimal': 'szybki', 'low': 'analiza', 'high': 'głęboka analiza'}; + const cIcon = complexityIcons[chunk.complexity] || ''; + const tLabel = thinkingLabels[chunk.thinking] || ''; + let badgeHTML = `${modelLabel}`; + if (cIcon && tLabel) badgeHTML += ` · ${cIcon} ${tLabel}`; + badgeHTML += ` · ${latencySec}s · ${costStr}`; if (currentModel === 'flash') { badgeHTML += ` · Lepsze odpowiedzi? Spróbuj Pro 🧠`; }