fix: умный роутер — по содержимому вопроса, не по наличию файлов
Роутинг: - Упоминание файлов/расширений/имён файлов в директории → Claude Code - "проверь смету", "создай файл", "скопируй" → Claude Code - "Какой НР?", "К_ВЛ?" (без упоминания файлов) → GLM-5 (быстро) Файлы в папке больше не триггерят Claude автоматически. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user