diff --git a/claude_bridge.py b/claude_bridge.py index 89a7e18..dfa695d 100644 --- a/claude_bridge.py +++ b/claude_bridge.py @@ -7,6 +7,7 @@ from pathlib import Path from typing import AsyncGenerator DOCKER_IMAGE = os.environ.get("CLAUDE_DOCKER_IMAGE", "smeta-claude-sandbox") +CLAUDE_MODEL = os.environ.get("CLAUDE_MODEL", "sonnet") # агентный расчёт смет DATA_DIR = Path(os.environ.get("DATA_DIR", "./smeta-web-data")) APP_DIR = Path(__file__).parent CLAUDE_CONFIG_DIR = os.environ.get( @@ -133,6 +134,21 @@ async def stream_claude( work_dir = get_work_dir(username, tab_id) session_id = get_session_id(username, tab_id) + # Страховочный слой расчёта: для смета-calc запросов пред-инжектим + # реальные цены корпуса в промпт — грунтинг гарантирован даже если + # модель не вызовет инструмент (закрывает пропуск вызова у слабых). + _ml = message.lower() + is_calc = (any(k in _ml for k in ("смет", "стоимост", "посчита", "рассчита", "расчёт", "расчет")) + and any(u in _ml for u in ("м3", "м2", "куб", "объ", " т ", "тонн", "шт", "пог", " км"))) + if is_calc: + try: + from claude_bridge_glm import _search_corpus + _cc = _search_corpus(message) + if _cc: + message = f"{message}\n\n[{_cc}]" + except Exception: + pass + # Pre-process xlsx files that openpyxl can't read → CSV _preprocess_xlsx(work_dir) @@ -153,6 +169,7 @@ async def stream_claude( claude_args = [ "-p", message, + "--model", CLAUDE_MODEL, "--output-format", "stream-json", "--verbose", "--allowedTools", diff --git a/main.py b/main.py index 0d4d2bc..cdb3689 100644 --- a/main.py +++ b/main.py @@ -68,7 +68,15 @@ elif AI_BACKEND == "hybrid": break is_agent = mentions_file or any(kw in msg_lower for kw in agent_actions) is_reference = any(kw in msg_lower for kw in reference_words) - if is_agent and not is_reference: + # Расчёт сметы по объёмам работ → агентный Claude (Sonnet): он тянет + # реальные цены корпуса и считает пошагово (страховка в claude_bridge). + is_smeta_calc = ( + any(k in msg_lower for k in ("посчита", "рассчита", "составь", "сделай смет")) + and ("смет" in msg_lower or "стоимост" in msg_lower) + and any(u in msg_lower for u in ("м3", "м2", "куб", "объ", " т ", "тонн", " шт", "пог", " км"))) + if is_smeta_calc: + stream_fn = _stream_claude # расчёт сметы — только агентный путь + elif is_agent and not is_reference: stream_fn = _stream_claude elif is_reference and not is_agent: stream_fn = _stream_glm