Skip to content

Commit 1322271

Browse files
committed
fix: Resolve UnboundLocalError for 're' module in technical system detection
ISSUE: UnboundLocalError at line 5387: cannot access local variable 're' where it is not associated with a value ROOT CAUSE: - Multiple uses of 're.search()' in has_your_system_pattern_rag detection (lines 5387-5393) - Python detects 're' as a local variable if it's assigned anywhere in the function - Previous fix only addressed line 3848, but line 5387 also uses 're' module FIX: - Import 're' module explicitly as 'regex_module_rag' within the detection block - Replace all 're.search()' calls with 'regex_module_rag.search()' in has_your_system_pattern_rag - This ensures no scope conflicts and prevents UnboundLocalError BENEFITS: - Fixes chat endpoint crash for technical system questions - Prevents UnboundLocalError in all code paths - Consistent with previous fix at line 3848
1 parent eb1d091 commit 1322271

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

backend/api/routers/chat_router.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5381,16 +5381,18 @@ def truncate_text(text: str, max_tokens: int) -> str:
53815381
])
53825382
# CRITICAL: Improved detection for "your system" questions
53835383
# Match patterns like "in your system", "your system", "system you", etc.
5384+
# CRITICAL: Import re module explicitly to avoid UnboundLocalError
5385+
import re as regex_module_rag
53845386
has_your_system_pattern_rag = (
53855387
"your system" in question_lower_rag or
53865388
"in your system" in question_lower_rag or
5387-
re.search(r'\bin\s+your\s+system\b', question_lower_rag) or # "in your system"
5388-
re.search(r'\byour\s+\w+\s+system\b', question_lower_rag) or # "your X system"
5389-
re.search(r'\bsystem\s+\w+\s+you\b', question_lower_rag) or # "system X you"
5390-
re.search(r'\bsystem\s+you\b', question_lower_rag) or # "system you"
5389+
regex_module_rag.search(r'\bin\s+your\s+system\b', question_lower_rag) or # "in your system"
5390+
regex_module_rag.search(r'\byour\s+\w+\s+system\b', question_lower_rag) or # "your X system"
5391+
regex_module_rag.search(r'\bsystem\s+\w+\s+you\b', question_lower_rag) or # "system X you"
5392+
regex_module_rag.search(r'\bsystem\s+you\b', question_lower_rag) or # "system you"
53915393
"bạn" in question_lower_rag and "hệ thống" in question_lower_rag or
53925394
"của bạn" in question_lower_rag or
5393-
re.search(r'\bhệ\s+thống\s+của\s+bạn\b', question_lower_rag) # "hệ thống của bạn"
5395+
regex_module_rag.search(r'\bhệ\s+thống\s+của\s+bạn\b', question_lower_rag) # "hệ thống của bạn"
53945396
)
53955397
# CRITICAL: Also check if this was already detected as StillMe query (from earlier detection)
53965398
# This ensures technical questions about "your system" are properly flagged for retry logic

0 commit comments

Comments
 (0)