From 87d4fde5c396a0048fe394a1999cc10564450236 Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Sat, 28 Mar 2026 06:51:08 +0100 Subject: [PATCH] fix(nordagpt): catch full URL hallucinations + remove manual model selector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Validator now catches https://nordabiznes.pl/company/slug (full URLs) - Also catches /firma/ URLs as fallback - Removed Flash/Pro model selector — Smart Router decides automatically - Removed "Spróbuj Pro" hints from response badges Co-Authored-By: Claude Opus 4.6 (1M context) --- nordabiz_chat.py | 10 +++++++--- templates/chat.html | 38 +------------------------------------- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/nordabiz_chat.py b/nordabiz_chat.py index 39be19b..16fe94a 100644 --- a/nordabiz_chat.py +++ b/nordabiz_chat.py @@ -198,9 +198,12 @@ class NordaBizChatEngine: logger.warning(f"NordaGPT hallucination blocked: '{link_text}' (slug: '{slug}') not in DB") return link_text # Keep text, remove link - text = re.sub(r'\[([^\]]+)\]\(/company/([a-z0-9-]+)\)', replace_link, text) + # Match both relative /company/slug AND absolute https://nordabiznes.pl/company/slug + text = re.sub(r'\[([^\]]+)\]\((?:https?://nordabiznes\.pl)?/company/([a-z0-9-]+)\)', replace_link, text) + # Also catch /firma/ in case AI uses old format + text = re.sub(r'\[([^\]]+)\]\((?:https?://nordabiznes\.pl)?/firma/([a-z0-9-]+)\)', replace_link, text) - # 2. Validate pill-style links + # 2. Validate pill-style links (HTML) def replace_pill_link(match): full_match = match.group(0) slug = match.group(1) @@ -213,7 +216,8 @@ class NordaBizChatEngine: logger.warning(f"NordaGPT hallucination blocked: pill link '{slug}' not in DB") return link_text - text = re.sub(r']*href=["\']/company/([a-z0-9-]+)["\'][^>]*>(.*?)', replace_pill_link, text) + text = re.sub(r']*href=["\'](?:https?://nordabiznes\.pl)?/company/([a-z0-9-]+)["\'][^>]*>(.*?)', replace_pill_link, text) + text = re.sub(r']*href=["\'](?:https?://nordabiznes\.pl)?/firma/([a-z0-9-]+)["\'][^>]*>(.*?)', replace_pill_link, text) # 3. Remove plain-text mentions of fake companies (bold or plain) # Catch patterns like "**Baumar**" or "Baumar" that appear as company names diff --git a/templates/chat.html b/templates/chat.html index 73853da..c1365b9 100755 --- a/templates/chat.html +++ b/templates/chat.html @@ -1546,40 +1546,7 @@ NordaGPT

NordaGPT

- -
- -
-
- Tryb pracy AI -

Flash wystarczy do większości pytań

-
-
-
- - Flash - Zalecany -
-

Szybki i inteligentny. Pytania o firmy, kontakty, usługi, branże.

- Wystarczający do większości pytań -
-
-
- 🧠 - Pro - Premium -
-

Głębsza analiza, porównania, raporty. Dłuższe odpowiedzi.

- Zużywa limit ~4x szybciej niż Flash -
-
-
+
@@ -2547,9 +2514,6 @@ async function sendMessage() { let badgeHTML = `${modelLabel}`; if (cIcon && tLabel) badgeHTML += ` · ${cIcon} ${tLabel}`; badgeHTML += ` · ${latencySec}s · ${costStr}`; - if (currentModel === 'flash') { - badgeHTML += ` · Lepsze odpowiedzi? Spróbuj Pro 🧠`; - } infoBadge.innerHTML = badgeHTML; streamContent.appendChild(infoBadge); if (chunk.cost_usd) updateMonthlyCost(chunk.cost_usd);