From 835b6a05df51ff6786948ed673d9e3b1da69239a Mon Sep 17 00:00:00 2001 From: wasrusgen Date: Tue, 2 Jun 2026 06:28:15 +0300 Subject: [PATCH] =?UTF-8?q?feat(crm):=20=D0=B8=D0=BD=D0=B4=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=20=D0=B1=D0=B0=D0=BB=D0=B0=D0=BD=D1=81?= =?UTF-8?q?=D0=B0=20AI-=D0=B4=D0=B2=D0=B8=D0=B6=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /api/ai-status — пинг в 1 токен, ловит low_balance. В CRM: точка в шапке (зелёная/красная) + плашка «AI-движок недоступен — пополните баланс». Без названия вендора (публичный репо + правило конфиденциальности). --- backend/elena_app.py | 11 +++++++++++ docs/crm.html | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/backend/elena_app.py b/backend/elena_app.py index 96cb9af..0ed8846 100644 --- a/backend/elena_app.py +++ b/backend/elena_app.py @@ -247,6 +247,17 @@ def run_tool(project_id, tool, tool_name, instruction, extra_context=None, max_t def health(): return jsonify({"ok": True, "model": MODEL, "time": now()}) +@app.route("/api/ai-status") +def ai_status(): + """Лёгкая проверка доступности AI-движка (пинг в 1 токен). Не бросает — всегда 200.""" + try: + client.messages.create(model=MODEL, max_tokens=1, messages=[{"role": "user", "content": "ping"}]) + return jsonify({"ok": True}) + except Exception as e: + msg = str(e) + low = ("credit balance" in msg.lower()) or ("too low" in msg.lower()) or ("billing" in msg.lower()) + return jsonify({"ok": False, "reason": "low_balance" if low else "error", "detail": msg[:200]}) + @app.route("/api/project/new", methods=["POST"]) def new_project(): data = request.get_json(force=True) or {} diff --git a/docs/crm.html b/docs/crm.html index 222e627..57eb142 100644 --- a/docs/crm.html +++ b/docs/crm.html @@ -161,7 +161,8 @@ body{font-family:'Inter',sans-serif;background:var(--bg);color:var(--text);displ -
@
wasrusgen1КОНСАЛТИНГ
CRM
Руслан
+
@
wasrusgen1КОНСАЛТИНГ
CRM
Руслан
+