From ad26c2ce98ac4cd5b2e55a3c90f3b72996f9bb89 Mon Sep 17 00:00:00 2001 From: anor Date: Tue, 24 Mar 2026 22:19:28 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=83=D0=BC=D0=BD=D1=8B=D0=B9=20=D1=80?= =?UTF-8?q?=D0=BE=D1=83=D1=82=D0=B5=D1=80=20=E2=80=94=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B4=D0=B5=D1=80=D0=B6=D0=B8=D0=BC=D0=BE=D0=BC?= =?UTF-8?q?=D1=83=20=D0=B2=D0=BE=D0=BF=D1=80=D0=BE=D1=81=D0=B0,=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D1=8E=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Роутинг: - Упоминание файлов/расширений/имён файлов в директории → Claude Code - "проверь смету", "создай файл", "скопируй" → Claude Code - "Какой НР?", "К_ВЛ?" (без упоминания файлов) → GLM-5 (быстро) Файлы в папке больше не триггерят Claude автоматически. Co-Authored-By: Claude Opus 4.6 (1M context) --- main.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 37f9945..84a8f07 100644 --- a/main.py +++ b/main.py @@ -27,18 +27,35 @@ elif AI_BACKEND == "auto": from claude_bridge import stream_claude as _stream_claude async def stream_claude(message: str, username: str, tab_id: str = "default"): - """Auto-route: files present or file ops → Claude Code, questions → GLM-5.""" + """Auto-route: file-related → Claude Code, normative questions → GLM-5. + + Logic: + 1. Message mentions files/creating/editing → Claude + 2. Message references uploaded file names → Claude + 3. Everything else (НР, СП, коэффициенты, правила) → GLM + """ + msg_lower = message.lower() + + # Keywords that need Claude Code (file operations) + claude_keywords = [ + "создай файл", "сохрани в", "запиши в", "сделай таблиц", + "перенеси данн", "измени файл", "отредактируй", "скопируй", + "проверь смет", "проверь файл", "открой файл", "покажи файл", + "загруж", "прикреп", "файл", ".xlsx", ".docx", ".pdf", ".csv", + ] + + # Check if message references files in work directory from claude_bridge_glm import get_work_dir as _get_wd work_dir = _get_wd(username, tab_id) - has_files = any( - f.is_file() and not f.name.startswith(".") - for f in work_dir.iterdir() - ) if work_dir.exists() else False + file_names = [] + if work_dir.exists(): + file_names = [f.name.lower() for f in work_dir.iterdir() + if f.is_file() and not f.name.startswith(".")] - file_keywords = ["создай файл", "сохрани в", "запиши в excel", "сделай таблицу", - "перенеси данные", "измени файл", "отредактируй", "проверь смет", - "проверь файл", "открой файл", "покажи файл"] - use_claude = has_files or any(kw in message.lower() for kw in file_keywords) + mentions_file = any(fn in msg_lower for fn in file_names) if file_names else False + has_keyword = any(kw in msg_lower for kw in claude_keywords) + + use_claude = mentions_file or has_keyword stream_fn = _stream_claude if use_claude else _stream_glm async for chunk in stream_fn(message, username, tab_id): yield chunk