{"id":505970,"date":"2026-12-03T16:59:16","date_gmt":"2026-12-03T13:59:16","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=505970"},"modified":"2026-12-03T16:59:16","modified_gmt":"2026-12-03T13:59:16","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=505970","title":{"rendered":"\u0411\u043e\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043f\u043e \u0431\u0430\u0437\u0435 \u0437\u043d\u0430\u043d\u0438\u0439, \u0430 \u0441\u0443\u043c\u043c\u044b \u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u0437\u0430 \u043d\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0434"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u043d\u043e\u044f\u0431\u0440\u0435 \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u0434\u0435\u043c\u043e \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438. \u041a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0432\u044b\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0430\u044f, \u043a\u043b\u0438\u043d\u0438\u043d\u0433 \u00ab\u0421\u0432\u0435\u0436\u0438\u0439 \u043c\u0435\u0442\u0440\u00bb, \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435. \u0410\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u0441\u0438\u0434\u0438\u0442 \u0432 \u0447\u0430\u0442\u0435 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0438 \u0432 Telegram, \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0431\u0430\u0437\u0435 \u0437\u043d\u0430\u043d\u0438\u0439, \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u043f\u0440\u0430\u0439\u0441\u0443 \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0437\u0430\u044f\u0432\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u0442\u043e\u043c \u0432\u0438\u0434\u0438\u0442 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440. \u0417\u0430\u0434\u0430\u0447\u0430 \u0442\u0438\u043f\u043e\u0432\u0430\u044f.<\/p>\n<p>\u041d\u0430\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u0442\u0430 \u0431\u043e\u0439\u043a\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e. \u0422\u0440\u0443\u0434\u043d\u0435\u0435 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0442\u043e\u0433\u043e, \u0447\u0435\u0433\u043e \u0432 \u0431\u0430\u0437\u0435 \u043d\u0435\u0442. \u041a\u043b\u0438\u0435\u043d\u0442 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e \u043c\u043e\u0439\u043a\u0443 \u0444\u0430\u0441\u0430\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 \u043e\u0431\u0449\u0438\u0445 \u0437\u043d\u0430\u043d\u0438\u0439 \u043e\u0445\u043e\u0442\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u0442, \u043a\u0430\u043a \u044d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e. \u041a\u043b\u0438\u0435\u043d\u0442 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u00ab\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430 54 \u043c\u0435\u0442\u0440\u0430\u00bb, \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0430\u043c\u0430 \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0438\u0442 \u0441\u0442\u0430\u0432\u043a\u0443 \u043d\u0430 \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f. \u0414\u043b\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0431\u0438\u0437\u043d\u0435\u0441\u0430 \u044d\u0442\u043e \u0445\u0443\u0436\u0435 \u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044f: \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0440\u0438\u0434\u0435\u0442 \u0441 \u0446\u0438\u0444\u0440\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0435\u043c\u0443 \u00ab\u043f\u043e\u043e\u0431\u0435\u0449\u0430\u043b\u0438\u00bb.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043a\u0430\u043a \u044d\u0442\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0443 \u043c\u0435\u043d\u044f. \u0421\u0442\u0435\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0439: Python 3.12, FastAPI, SQLite, aiogram 3, pydantic. \u041c\u043e\u0434\u0435\u043b\u044c DeepSeek \u0447\u0435\u0440\u0435\u0437 OpenRouter, \u0437\u0430\u043f\u0430\u0441\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0441\u0431\u043e\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439.<\/p>\n<h3>\u0412\u0441\u044f \u0431\u0430\u0437\u0430 \u0432 \u043f\u0440\u043e\u043c\u043f\u0442\u0435, \u0438 \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e<\/h3>\n<p>\u041b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u2013 \u0433\u0434\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a. \u0417\u0434\u0435\u0441\u044c \u0435\u0433\u043e \u043d\u0435\u0442. \u0412 \u0431\u0430\u0437\u0435 16 \u0441\u0442\u0430\u0442\u0435\u0439: \u0432\u0438\u0434\u044b \u0443\u0431\u043e\u0440\u043a\u0438, \u0447\u0442\u043e \u0432\u0445\u043e\u0434\u0438\u0442, \u0437\u043e\u043d\u0430 \u0432\u044b\u0435\u0437\u0434\u0430, \u043e\u043f\u043b\u0430\u0442\u0430, \u043f\u0435\u0440\u0435\u043d\u043e\u0441, \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0435 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0412\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u043e\u043a\u043e\u043b\u043e \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0442\u044b\u0441\u044f\u0447 \u0437\u043d\u0430\u043a\u043e\u0432. \u0420\u0435\u0437\u0430\u0442\u044c \u0438\u0445 \u043d\u0430 \u0447\u0430\u043d\u043a\u0438, \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0438 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0442\u044c top-k \u0440\u0430\u0434\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430 \u2013 \u043b\u0438\u0448\u043d\u044f\u044f \u0434\u0435\u0442\u0430\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043b\u043e\u043c\u0430\u0442\u044c\u0441\u044f. \u041c\u043e\u0434\u0435\u043b\u044c \u0432\u0438\u0434\u0438\u0442 \u0432\u0441\u044e \u0431\u0430\u0437\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0438 \u0441\u0430\u043c\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e.<\/p>\n<p>\u041f\u0440\u043e\u043c\u043f\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043d\u043e\u0432\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"python\">def render_prompt(db, state, today):    from .texts import PROMPT_RULES, WEEKDAYS_SHORT    # Re-read on every turn. Panel changes never need a process restart.    return '\\n'.join((PROMPT_RULES,        'COMPANY\\n' + dumps(db.seed('company.json')),        'KB\\n' + dumps(public_articles(db)),        'PRICES\\n' + dumps(prices(db)),        'TODAY\\n' + today.isoformat() + '\\n' + WEEKDAYS_SHORT[today.weekday()] + ' Europe\/Moscow',        'STATE\\n' + dumps(state)))<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper\"><\/span><\/a><\/div><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0437-\u0437\u0430 \u043f\u0430\u043d\u0435\u043b\u0438 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430, \u0433\u0434\u0435 \u043e\u043d \u043f\u0440\u0430\u0432\u0438\u0442 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u043f\u0440\u0430\u0439\u0441. \u041f\u043e\u043c\u0435\u043d\u044f\u043b \u0441\u0442\u0430\u0432\u043a\u0443 \u0433\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u0443\u0431\u043e\u0440\u043a\u0438 \u2013 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0436\u0435 \u043e\u0442\u0432\u0435\u0442 \u0431\u043e\u0442\u0430 \u0438\u0434\u0435\u0442 \u043f\u043e \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0430\u0432\u043a\u0435, \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438 \u043a\u044d\u0448\u0435\u0439. \u041d\u0430 \u044d\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442: \u043e\u043d \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0442\u0430\u0442\u044c\u044e \u0438 \u0446\u0435\u043d\u0443 \u0432 \u0431\u0430\u0437\u0435 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u0443\u0436\u0435 \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0414\u0430\u0442\u0430 \u0432 \u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u043d\u0443\u0436\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0433\u043b\u0430 \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u00ab\u0432 \u0441\u0443\u0431\u0431\u043e\u0442\u0443\u00bb \u0438\u043b\u0438 \u00ab20 \u043d\u043e\u044f\u0431\u0440\u044f\u00bb \u0432 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u043d\u0443\u044e \u0434\u0430\u0442\u0443. \u041d\u043e \u044d\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c \u0432\u0441\u0435 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0434\u0430\u0442\u0443 \u043a\u043e\u0434.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0442\u0435\u043d, \u043f\u043e\u0438\u0441\u043a \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c. \u0414\u043b\u044f \u0431\u0430\u0437\u044b \u043c\u0430\u043b\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441\u0430 \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u0435\u0433\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u043b\u044e\u0441.<\/p>\n<h3>\u041c\u043e\u0434\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 JSON \u0441 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u0435\u043c<\/h3>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u043f\u0438\u0448\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u041e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 JSON, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 pydantic:<\/p>\n<pre><code class=\"python\">class LLMOutput(BaseModel):    model_config = ConfigDict(strict=True)    action: Literal['answer','smalltalk','collect','handoff','out_of_scope']    reply: str    kb_refs: list[str]    fields: dict = Field(default_factory=dict)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p><code>action<\/code> \u2013 \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c: \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043f\u043e \u0431\u0430\u0437\u0435, \u043f\u043e\u0437\u0434\u043e\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0437\u0430\u044f\u0432\u043a\u0443, \u043f\u043e\u0437\u0432\u0430\u0442\u044c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0438\u043b\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0435\u0442. \u0412 <code>kb_refs<\/code> \u043e\u043d\u0430 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u0442 id \u0441\u0442\u0430\u0442\u0435\u0439, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0438\u0440\u0430\u043b\u0430\u0441\u044c. \u0412 <code>fields<\/code> \u043a\u043b\u0430\u0434\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u0441\u043a\u0430\u0437\u0430\u043b \u0434\u043b\u044f \u0437\u0430\u044f\u0432\u043a\u0438: \u0432\u0438\u0434 \u0443\u0431\u043e\u0440\u043a\u0438, \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u0430\u0434\u0440\u0435\u0441, \u0434\u0430\u0442\u0443, \u0438\u043c\u044f, \u0442\u0435\u043b\u0435\u0444\u043e\u043d.<\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u043d\u0435 \u043f\u0440\u043e\u0448\u0435\u043b \u0441\u0445\u0435\u043c\u0443 (\u043b\u0438\u0448\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 <code>action<\/code>, \u043d\u0435\u0442 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f) \u2013 \u0437\u0430\u043f\u0440\u043e\u0441 \u0443\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0430\u0441\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u0435 \u043f\u0440\u043e\u0448\u0435\u043b \u0438 \u0442\u0430\u043c \u2013 \u043a\u043b\u0438\u0435\u043d\u0442 \u0432\u0438\u0434\u0438\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0441 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u00ab\u041f\u043e\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430\u00bb. JSON \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0439\u0442\u0438 \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u044b\u043c \u0432 markdown-\u0431\u043b\u043e\u043a \u0438\u043b\u0438 \u0441 BOM \u0432 \u043d\u0430\u0447\u0430\u043b\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0430\u0440\u0441\u0435\u0440 \u0431\u0435\u0440\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 JSON-\u043e\u0431\u044a\u0435\u043a\u0442 \u0447\u0435\u0440\u0435\u0437 <code>json.JSONDecoder().raw_decode<\/code>, \u0430 \u043d\u0435 \u0436\u0430\u0434\u043d\u043e\u0439 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043a\u043e\u0439. \u0421\u043a\u043e\u0431\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u043a \u0435\u0433\u043e \u043d\u0435 \u0441\u043c\u0443\u0449\u0430\u044e\u0442.<\/p>\n<h3>\u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0434<\/h3>\n<p>\u0412 \u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e: \u043e\u0442\u0432\u0435\u0447\u0430\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0431\u0430\u0437\u0435 \u0438 \u0443\u043a\u0430\u0436\u0438 \u0441\u0442\u0430\u0442\u044c\u0438. \u041c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043b\u0443\u0448\u0430\u0435\u0442\u0441\u044f. \u041d\u043e \u00ab\u043e\u0431\u044b\u0447\u043d\u043e\u00bb \u043c\u0435\u043d\u044f \u043d\u0435 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043a\u043e\u0434 \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442 \u0438\u0437 <code>kb_refs<\/code> \u0432\u0441\u0435 id, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u0431\u0430\u0437\u0435 \u043d\u0435\u0442, \u0430 \u043f\u043e\u0442\u043e\u043c \u0440\u0435\u0448\u0430\u0435\u0442, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043b\u0438 \u0442\u0435\u043a\u0441\u0442:<\/p>\n<pre><code class=\"python\">refs = []seen = set()for ref in output.kb_refs:    article = next((a for a in articles if a['id'] == ref), None)    if article and ref not in seen:        refs.append({'id': ref, 'title': article['title'], 'url': ...})        seen.add(ref)...elif output.action == 'answer':    if refs and amount_allowed(output.reply, articles, prices):        self.db.add_message(cid, 'bot', client_text(output.reply), kb_refs=refs)    elif not continues:        self._out_of_scope(cid)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0442\u0435\u043a\u0441\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u0442 \u0432\u043e\u043e\u0431\u0449\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0443\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u00ab\u0412 \u0431\u0430\u0437\u0435 \u0437\u043d\u0430\u043d\u0438\u0439 \u043d\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441. \u041c\u043e\u0433\u0443 \u043f\u043e\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430.\u00bb \u042d\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 \u0438\u0437 \u043a\u043e\u0434\u0430, \u0430 \u043d\u0435 \u0442\u0435\u043a\u0441\u0442 \u043c\u043e\u0434\u0435\u043b\u0438. \u041c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0433\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 <code>reply<\/code> \u0432\u0435\u0436\u043b\u0438\u0432\u043e\u0435 \u00ab\u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435 \u0437\u043d\u0430\u044e, \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e\u2026\u00bb, \u0438 \u0432\u043e\u0442 \u044d\u0442\u043e \u00ab\u043e\u0431\u044b\u0447\u043d\u043e\u00bb \u043a\u0430\u043a \u0440\u0430\u0437 \u043e\u043f\u0430\u0441\u043d\u043e.<\/p>\n<p>\u041f\u043e\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442 \u0432\u0438\u0434\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u0438. \u0412 \u0432\u0435\u0431\u0435 \u044d\u0442\u043e \u044f\u043a\u043e\u0440\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u0432 Telegram \u2013 \u0441\u0442\u0440\u043e\u043a\u0430 \u00ab\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a: \u2026\u00bb. \u041a\u043b\u0438\u0435\u043d\u0442\u0443 \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442, \u0430 \u043c\u043d\u0435 \u043f\u0440\u0438 \u0440\u0430\u0437\u0431\u043e\u0440\u0435 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u0441\u0440\u0430\u0437\u0443 \u0432\u0438\u0434\u043d\u043e, \u043d\u0430 \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0441\u043b\u0430\u043b\u0430\u0441\u044c.<\/p>\n<p>\u041e\u0442\u043a\u0430\u0437 \u0442\u043e\u0436\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u043e\u043c. \u0415\u0441\u043b\u0438 \u0432 \u0431\u0430\u0437\u0435 \u043f\u0440\u044f\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0447\u0435\u0433\u043e-\u0442\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043d\u0430 \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0431 \u0443\u0441\u043b\u0443\u0433\u0430\u0445 \u0435\u0441\u0442\u044c \u0444\u0440\u0430\u0437\u0430 \u00ab\u041f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0441\u043a\u043b\u0430\u0434\u044b \u0438 \u043c\u043e\u0439\u043a\u0443 \u0444\u0430\u0441\u0430\u0434\u043e\u0432 \u043d\u0435 \u0431\u0435\u0440\u0435\u043c\u00bb. \u041d\u0430 \u0436\u0438\u0432\u043e\u043c \u043f\u0440\u043e\u0433\u043e\u043d\u0435 \u0431\u043e\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0444\u0430\u0441\u0430\u0434\u0430\u0445 \u0432\u0435\u0436\u043b\u0438\u0432\u043e \u043e\u0442\u043a\u0430\u0437\u0430\u043b \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a.<\/p>\n<h3>\u0420\u0443\u0431\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0432 \u0431\u0430\u0437\u0435<\/h3>\n<p>\u0421\u0430\u043c\u0430\u044f \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u2013 \u0441\u0443\u043c\u043c\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0442\u0432\u0435\u0442\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u0434 \u0438\u0449\u0435\u0442 \u0447\u0438\u0441\u043b\u0430 \u0441 \u00ab\u20bd\u00bb \u0438\u043b\u0438 \u00ab\u0440\u0443\u0431\u00bb \u0438 \u0441\u0432\u0435\u0440\u044f\u0435\u0442 \u0438\u0445 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0441\u0443\u043c\u043c\u0430\u043c\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u043f\u0440\u0430\u0439\u0441\u0430:<\/p>\n<pre><code class=\"python\">def ruble_amounts(text):    # Spaces group thousands only when followed by exactly three digits.    return {re.sub(r'[ \\u00a0\\u202f]', '', m.group(1)).replace(',', '.')            for m in re.finditer(r'(?&lt;![0-9])([0-9]+(?:[ \\u00a0\\u202f][0-9]{3})*(?:[.,][0-9]+)?)\\s*(?:\u20bd|\u0440\u0443\u0431)',                                 text, re.IGNORECASE)}def amount_allowed(reply, articles, prices):    allowed = ruble_amounts('\\n'.join(a['body'] for a in articles))    for item in prices['services'].values():        allowed.update(str(item[key]) for key in ('rate_per_m2', 'min_total'))    for item in prices['extras'].values():        allowed.add(str(item['unit_price']))    return ruble_amounts(reply) &lt;= allowed# \u041f\u0440\u043e\u0433\u043e\u043d \u043d\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0431\u0430\u0437\u0435 \u0437\u043d\u0430\u043d\u0438\u0439 \u0438 \u043f\u0440\u0430\u0439\u0441\u0435 \u0434\u0435\u043c\u043efor r in ['\u0413\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u0431\u043e\u0440\u043a\u0430 \u0441\u0442\u043e\u0438\u0442 190 \u20bd \u0437\u0430 \u043c\u00b2, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 6 900 \u20bd.',          '\u0413\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0430 54 \u043c\u00b2 \u043e\u0431\u043e\u0439\u0434\u0435\u0442\u0441\u044f \u0432 10 260 \u20bd.',          '\u0411\u0443\u0434\u0435\u0442 1800 \u0440\u0443\u0431\u043b\u0435\u0439.',          '\u0411\u0443\u0434\u0435\u0442 \u0442\u044b\u0441\u044f\u0447\u0430 \u0432\u043e\u0441\u0435\u043c\u044c\u0441\u043e\u0442 \u0440\u0443\u0431\u043b\u0435\u0439.']:    print(amount_allowed(r, kb, prices), '|', r)# True  | \u0413\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u0431\u043e\u0440\u043a\u0430 \u0441\u0442\u043e\u0438\u0442 190 \u20bd \u0437\u0430 \u043c\u00b2, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 6 900 \u20bd.# False | \u0413\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0430 54 \u043c\u00b2 \u043e\u0431\u043e\u0439\u0434\u0435\u0442\u0441\u044f \u0432 10 260 \u20bd.# False | \u0411\u0443\u0434\u0435\u0442 1800 \u0440\u0443\u0431\u043b\u0435\u0439.# True  | \u0411\u0443\u0434\u0435\u0442 \u0442\u044b\u0441\u044f\u0447\u0430 \u0432\u043e\u0441\u0435\u043c\u044c\u0441\u043e\u0442 \u0440\u0443\u0431\u043b\u0435\u0439.<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0422\u044b\u0441\u044f\u0447\u0438 \u043f\u0438\u0448\u0443\u0442 \u0442\u043e \u0441\u043b\u0438\u0442\u043d\u043e, \u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b, \u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0440\u0430\u0437\u0440\u044b\u0432\u043d\u044b\u0439 \u0438\u043b\u0438 \u0443\u0437\u043a\u0438\u0439 \u043f\u0440\u043e\u0431\u0435\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u043f\u0435\u0440\u0435\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435\u043c \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f. \u00ab6 900 \u20bd\u00bb \u0438 \u00ab6900 \u0440\u0443\u0431.\u00bb \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 <code>6900<\/code>.<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f. 54 \u00d7 190 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e 10 260, \u0441\u0443\u043c\u043c\u0430 \u0432\u0435\u0440\u043d\u0430\u044f, \u0430 \u043e\u0442\u0432\u0435\u0442 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u0442. \u0422\u0430\u043a \u0438 \u0437\u0430\u0434\u0443\u043c\u0430\u043d\u043e. \u0418\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u043e\u0431\u0449\u0435, \u044d\u0442\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043f\u0440\u043e\u043c\u043f\u0442\u0435. \u0415\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0430\u0437\u0432\u0430\u043b \u0432\u0438\u0434 \u0443\u0431\u043e\u0440\u043a\u0438 \u0438 \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u043c\u043e\u0434\u0435\u043b\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0438\u0445 \u0432 <code>fields<\/code>, \u0430 \u0440\u0430\u0441\u0447\u0435\u0442 \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0434\u0435\u043b\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>quote()<\/code>: \u0441\u0442\u0430\u0432\u043a\u0430 \u043d\u0430 \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043a\u0430\u0437, \u0434\u043e\u043f. \u0443\u0441\u043b\u0443\u0433\u0438 \u043f\u043e\u0448\u0442\u0443\u0447\u043d\u043e. \u0412 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u00ab\u0433\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f 54 \u043c2 \u0438 3 \u043e\u043a\u043d\u0430\u00bb \u043a\u043b\u0438\u0435\u043d\u0442 \u0432\u0438\u0434\u0438\u0442 10 260 \u20bd + 1 350 \u20bd = 11 610 \u20bd, \u0438 \u044d\u0442\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430. \u041c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043c\u043e\u0436\u0435\u0442 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f. \u041a\u043e\u0434 \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430, \u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 \u0441 \u0434\u043e\u043f. \u0443\u0441\u043b\u0443\u0433\u0430\u043c\u0438 \u043e\u043d \u0442\u043e\u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u0442.<\/p>\n<p>\u0427\u0435\u0442\u0432\u0435\u0440\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2013 \u0447\u0435\u0441\u0442\u043d\u0430\u044f \u0434\u044b\u0440\u0430. \u0421\u0443\u043c\u043c\u0430 \u043f\u0440\u043e\u043f\u0438\u0441\u044c\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442, \u0447\u0438\u0441\u043b\u0430 \u0431\u0435\u0437 \u0437\u043d\u0430\u043a\u0430 \u0440\u0443\u0431\u043b\u044f \u0442\u043e\u0436\u0435. \u0415\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0447\u043d\u0435\u0442 \u0442\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c.<\/p>\n<h3>\u041a\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442<\/h3>\n<p>OpenRouter \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 5xx, \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u044f\u043d\u0435\u0442 \u0434\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430, \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432\u043c\u0435\u0441\u0442\u043e JSON. \u041d\u0430 \u043e\u0434\u0438\u043d \u0445\u043e\u0434 \u0443 \u043c\u0435\u043d\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0434\u0432\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438:<\/p>\n<pre><code class=\"python\">for model in (self.settings.llm_model, self.settings.llm_fallback_model):    if self.spent() &gt;= self.settings.llm_daily_budget_usd:        raise BudgetReached()    try:        content, usage = await self.provider.complete(messages, model, text=text, state=state)        self.charge(usage)        return parse_output(content)    except httpx.HTTPStatusError as exc:        if exc.response.status_code &lt; 500:            break    except (httpx.TimeoutException, httpx.TransportError, ValueError, ValidationError,            KeyError, IndexError, TypeError):        continueraise LLMUnavailable()<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>(\u0421\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043e: \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435 \u0435\u0449\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0443\u0447\u0435\u0442 \u0440\u0430\u0441\u0445\u043e\u0434\u0430 \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0435.)<\/p>\n<p>\u041e\u0448\u0438\u0431\u043a\u0430 4xx \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435, \u0438 \u0437\u0430\u043f\u0430\u0441\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0435\u0435 \u043d\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0446\u0438\u043a\u043b \u043e\u0431\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f. 5xx, \u0442\u0430\u0439\u043c\u0430\u0443\u0442, \u043a\u0440\u0438\u0432\u043e\u0439 JSON \u2013 \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u041f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u043e\u0439 \u043a\u043e\u0434 \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0431\u044e\u0434\u0436\u0435\u0442 \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c. \u0412 \u0434\u0435\u043c\u043e \u043e\u043d \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439, \u0438 \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043d\u0447\u0430\u0435\u0442\u0441\u044f, \u0431\u043e\u0442 \u0442\u0430\u043a \u0438 \u043f\u0438\u0448\u0435\u0442, \u0447\u0442\u043e \u043b\u0438\u043c\u0438\u0442 \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u043d, \u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430.<\/p>\n<p>\u041d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0432\u044b\u043b\u0435\u0437\u043b\u0430 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0411\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u0437\u0430\u0441\u0442\u0440\u0435\u0432\u0430\u043b \u043f\u043e\u0441\u0440\u0435\u0434\u0438 \u0437\u0430\u044f\u0432\u043a\u0438. \u0413\u043b\u0443\u043f\u043e, \u0432\u0435\u0434\u044c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u00ab54\u00bb \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u043f\u043b\u043e\u0449\u0430\u0434\u0438, \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u0430. \u0422\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u0431\u043e\u0442 \u0436\u0434\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u043f\u043e\u043b\u0435, \u043a\u043e\u0434 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0430\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442: \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u0442\u0435\u043b\u0435\u0444\u043e\u043d, \u0434\u0430\u0442\u0443 \u0432\u0440\u043e\u0434\u0435 \u00ab\u0437\u0430\u0432\u0442\u0440\u0430\u00bb \u0438\u043b\u0438 \u00ab20.11\u00bb, \u0432\u0438\u0434 \u0443\u0431\u043e\u0440\u043a\u0438. \u0415\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430, \u0438\u043c\u044f \u0438 \u0430\u0434\u0440\u0435\u0441 \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0435\u0441\u0442\u044c, \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0434\u043b\u0438\u043d\u044b. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b \u043a\u043e\u0434, \u0433\u043b\u0430\u0432\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u044c\u044e. \u0412 \u0442\u0435\u0441\u0442\u0430\u0445 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439: \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0438\u0448\u0435\u0442 \u00ab54\u00bb, \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043b\u043e\u0449\u0430\u0434\u044c 80, \u0432 \u0437\u0430\u044f\u0432\u043a\u0443 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 54.<\/p>\n<p>\u0411\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u043e\u0442 \u0443\u0436\u0435 \u043d\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430. \u041d\u043e \u043a\u043b\u0438\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u0437\u0430\u043a\u0430\u0437\u0430\u0442\u044c \u0443\u0431\u043e\u0440\u043a\u0443, \u0447\u0435\u0440\u0435\u0437 \u043a\u043d\u043e\u043f\u043a\u0443 \u00ab\u041e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u0437\u0430\u044f\u0432\u043a\u0443\u00bb \u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043e \u00ab\u041f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044c\u00bb.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u044b \u0431\u0435\u0437 \u0441\u0435\u0442\u0438<\/h3>\n<p>\u0412\u0441\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0445\u043e\u0434\u044f\u0442 \u043d\u0438 \u0432 OpenRouter, \u043d\u0438 \u0432 Telegram, \u043d\u0438 \u0432 CRM. \u041c\u043e\u0434\u0435\u043b\u044c \u0432 \u0442\u0435\u0441\u0442\u0430\u0445 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 <code>ScriptedLLM<\/code>. \u042d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043e\u0442\u0434\u0430\u0435\u0442 \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u0422\u0430\u043a \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430 \u0436\u0438\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u043e \u0437\u0430\u043a\u0430\u0437\u0443: \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u043b\u0438\u0448\u043d\u044e\u044e \u0441\u0443\u043c\u043c\u0443, \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043e\u0431\u0435\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043f\u043e\u0434\u0440\u044f\u0434.<\/p>\n<pre><code class=\"python\">async def test_rejected_reply_still_out_of_scope_without_lead_flow(db):    provider = ScriptedLLM([output('answer', '\u0411\u0443\u0434\u0435\u0442 1 800 \u20bd', ['ceny'])])    cid = db.create_conversation()    replies = await Engine(db, llm=provider).handle_user_message(cid, '\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u043e\u0438\u0442?')    assert replies[-1]['text'] == texts.OUT_OF_SCOPE@pytest.mark.parametrize(\"action,refs\", [(\"out_of_scope\", []), (\"answer\", []), (\"answer\", [\"missing-id\"])])def test_out_of_scope_fixed_verbatim_not_model_text(harness_factory, llm_response, action, refs):    h = harness_factory([llm_response(action, \"\u041d\u0415 \u0414\u041e\u041f\u0423\u0421\u041a\u0410\u0422\u042c \u0412 \u041e\u0422\u0412\u0415\u0422\", kb_refs=refs)])    ...<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0442\u0435\u0441\u0442\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043e \u0446\u0435\u043d\u0430\u0445, \u043d\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0443\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432 \u0431\u0430\u0437\u0435 \u043d\u0435\u0442. \u041a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0443. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0438\u0448\u0435\u0442 \u00ab\u041d\u0415 \u0414\u041e\u041f\u0423\u0421\u041a\u0410\u0422\u042c \u0412 \u041e\u0422\u0412\u0415\u0422\u00bb \u0432 \u0442\u0440\u0435\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445, \u0438 \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043d\u0435 \u0434\u043e\u0448\u043b\u0430.<\/p>\n<p>\u0412\u0441\u0435\u0433\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 629 \u0442\u0435\u0441\u0442\u043e\u0432, \u0438\u0437 \u043d\u0438\u0445 241 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439: \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043f\u0443\u043d\u043a\u0442\u043e\u043c \u0442\u0435\u0445\u0437\u0430\u0434\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442. \u041f\u043e\u043b\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u043e\u043d \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u043a\u043e\u043b\u043e 20 \u0441\u0435\u043a\u0443\u043d\u0434. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u043d\u0430 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0432\u0435\u0441\u044c \u043f\u0443\u0442\u044c \u0447\u0435\u0440\u0435\u0437 HTTP: \u0432\u043e\u043f\u0440\u043e\u0441, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u043e\u0442 \u0431\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442, \u0437\u0430\u0442\u0435\u043c \u0437\u0430\u044f\u0432\u043a\u0430 \u043e\u0442 \u0432\u044b\u0431\u043e\u0440\u0430 \u0443\u0441\u043b\u0443\u0433\u0438 \u0434\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f, \u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u0432 \u043b\u043e\u0433\u0430\u0445 \u043d\u0435\u0442 \u043d\u0438 \u043a\u043b\u044e\u0447\u0430, \u043d\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0422\u0435\u0441\u0442\u044b \u043d\u0435 \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442 \u0436\u0438\u0432\u044b\u0435 \u043f\u0440\u043e\u0433\u043e\u043d\u044b. \u041d\u0430 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0434\u0435\u043c\u043e \u0441 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u043f\u0440\u043e\u0433\u043d\u0430\u043b\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0431\u0430\u0437\u0435, \u0440\u0430\u0441\u0447\u0435\u0442\u044b, \u0437\u0430\u044f\u0432\u043a\u0438 \u0441 \u0441\u0430\u0439\u0442\u0430 \u0438 \u0438\u0437 Telegram, \u043d\u0435\u0432\u0435\u0440\u043d\u0443\u044e \u043f\u043b\u043e\u0449\u0430\u0434\u044c (5 \u0438 1000 \u043c\u00b2), \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u043a\u043e\u043d, \u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c (\u043e\u0442\u0432\u0435\u0442 \u043f\u0440\u0438\u0448\u0435\u043b \u043f\u043e \u0431\u0430\u0437\u0435 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c). \u0414\u0432\u0430 \u043a\u0440\u0443\u0433\u0430 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430\u0448\u043b\u0438 \u043e\u043a\u043e\u043b\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u0430 \u043d\u0435\u0434\u043e\u0447\u0435\u0442\u043e\u0432: \u0431\u043e\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u0440\u0430\u0437\u0443, \u0432 Telegram \u0441\u0442\u0440\u043e\u043a\u0438 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c, \u0432\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u044f\u0432\u043a\u0430 \u0432 \u0442\u043e\u043c \u0436\u0435 \u0447\u0430\u0442\u0435 \u043f\u0443\u0442\u0430\u043b\u0430\u0441\u044c \u0441 \u043f\u0435\u0440\u0432\u043e\u0439, \u0434\u043e\u043f. \u0443\u0441\u043b\u0443\u0433\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u0443\u0431\u0440\u0430\u0442\u044c. \u041f\u043e\u0434 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0441\u043b\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b.<\/p>\n<h3>\u0427\u0435\u0433\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0435\u0442<\/h3>\n<p>\u0411\u043e\u0442 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u0442 \u0438 \u043d\u0435 \u0432\u0438\u0434\u0438\u0442 \u0441\u0442\u0430\u0442\u0443\u0441 \u0437\u0430\u044f\u0432\u043a\u0438 \u0432 CRM. \u0427\u0442\u043e\u0431\u044b \u043e\u043d \u0441\u0442\u0430\u043b \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u043c \u0430\u0433\u0435\u043d\u0442\u043e\u043c, \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0445\u043e\u0434\u044f\u0442 \u0432 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u0432 CRM, \u0430 \u044d\u0442\u043e \u0443\u0436\u0435 \u0434\u0440\u0443\u0433\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430. \u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u044124 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430, \u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u0438 API, \u043a \u0436\u0438\u0432\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0430\u043b\u0443 \u044f \u0435\u0435 \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u043b. SQLite \u0438 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0433\u043e\u0434\u044f\u0442\u0441\u044f \u0434\u043b\u044f \u0434\u0435\u043c\u043e \u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438\u0445 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044f\u0442\u044c.<\/p>\n<p>\u041f\u043e \u0434\u0435\u043d\u044c\u0433\u0430\u043c \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u044b\u0448\u043b\u043e \u043e\u043a\u043e\u043b\u043e 0,001\u20130,003 \u0434\u043e\u043b\u043b\u0430\u0440\u0430 \u0437\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u0434\u0438\u0430\u043b\u043e\u0433 \u0441 \u0437\u0430\u044f\u0432\u043a\u043e\u0439, \u043e\u0442\u0432\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 1\u20133 \u0441\u0435\u043a\u0443\u043d\u0434\u044b. \u0412\u0441\u044f \u0431\u0430\u0437\u0430 \u0432 \u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043e\u0431\u044a\u0435\u043c\u0435 \u043f\u043e\u0447\u0442\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442.<\/p>\n<p>\u041c\u043e\u0434\u0435\u043b\u0438 \u044f \u0434\u043e\u0432\u0435\u0440\u044f\u044e \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043d\u0430\u0439\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u044e \u0438 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442. \u0412\u0441\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0434: \u0447\u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u0443\u043c\u043c\u0430 \u0435\u0441\u0442\u044c \u0432 \u0431\u0430\u0437\u0435, \u0447\u0442\u043e \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u043e\u0442 10 \u0434\u043e 500 \u043c\u00b2, \u0447\u0442\u043e \u0434\u0430\u0442\u0430 \u043d\u0435 \u0440\u0430\u043d\u044c\u0448\u0435 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0435\u0439 \u0438 \u043d\u0435 \u0434\u0430\u043b\u044c\u0448\u0435 60 \u0434\u043d\u0435\u0439. \u0410 \u0442\u0430\u043c, \u0433\u0434\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u0431\u043e\u0442 \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u0438 \u0437\u043e\u0432\u0435\u0442 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430.<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1115596\/\">https:\/\/habr.com\/ru\/articles\/1115596\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u043d\u043e\u044f\u0431\u0440\u0435 \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u0434\u0435\u043c\u043e \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438. \u041a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0432\u044b\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0430\u044f, \u043a\u043b\u0438\u043d\u0438\u043d\u0433 \u00ab\u0421\u0432\u0435\u0436\u0438\u0439 \u043c\u0435\u0442\u0440\u00bb, \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435. \u0410\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u0441\u0438\u0434\u0438\u0442 \u0432 \u0447\u0430\u0442\u0435 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0438 \u0432 Telegram, \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0431\u0430\u0437\u0435 \u0437\u043d\u0430\u043d\u0438\u0439, \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u043f\u0440\u0430\u0439\u0441\u0443 \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0437\u0430\u044f\u0432\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u0442\u043e\u043c \u0432\u0438\u0434\u0438\u0442 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440. \u0417\u0430\u0434\u0430\u0447\u0430 \u0442\u0438\u043f\u043e\u0432\u0430\u044f.\u041d\u0430\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u0442\u0430 \u0431\u043e\u0439\u043a\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e. \u0422\u0440\u0443\u0434\u043d\u0435\u0435 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0442\u043e\u0433\u043e, \u0447\u0435\u0433\u043e \u0432 \u0431\u0430\u0437\u0435 \u043d\u0435\u0442. \u041a\u043b\u0438\u0435\u043d\u0442 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e \u043c\u043e\u0439\u043a\u0443 \u0444\u0430\u0441\u0430\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 \u043e\u0431\u0449\u0438\u0445 \u0437\u043d\u0430\u043d\u0438\u0439 \u043e\u0445\u043e\u0442\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u0442, \u043a\u0430\u043a \u044d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e. \u041a\u043b\u0438\u0435\u043d\u0442 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u00ab\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430 54 \u043c\u0435\u0442\u0440\u0430\u00bb, \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0430\u043c\u0430 \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0438\u0442 \u0441\u0442\u0430\u0432\u043a\u0443 \u043d\u0430 \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f. \u0414\u043b\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0431\u0438\u0437\u043d\u0435\u0441\u0430 \u044d\u0442\u043e \u0445\u0443\u0436\u0435 \u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044f: \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0440\u0438\u0434\u0435\u0442 \u0441 \u0446\u0438\u0444\u0440\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0435\u043c\u0443 \u00ab\u043f\u043e\u043e\u0431\u0435\u0449\u0430\u043b\u0438\u00bb.\u041d\u0438\u0436\u0435 \u043a\u0430\u043a \u044d\u0442\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0443 \u043c\u0435\u043d\u044f. \u0421\u0442\u0435\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0439: Python 3.12, FastAPI, SQLite, aiogram 3, pydantic. \u041c\u043e\u0434\u0435\u043b\u044c DeepSeek \u0447\u0435\u0440\u0435\u0437 OpenRouter, \u0437\u0430\u043f\u0430\u0441\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0441\u0431\u043e\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439.\u0412\u0441\u044f \u0431\u0430\u0437\u0430 \u0432 \u043f\u0440\u043e\u043c\u043f\u0442\u0435, \u0438 \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u041b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u2013 \u0433\u0434\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a. \u0417\u0434\u0435\u0441\u044c \u0435\u0433\u043e \u043d\u0435\u0442. \u0412 \u0431\u0430\u0437\u0435 16 \u0441\u0442\u0430\u0442\u0435\u0439: \u0432\u0438\u0434\u044b \u0443\u0431\u043e\u0440\u043a\u0438, \u0447\u0442\u043e \u0432\u0445\u043e\u0434\u0438\u0442, \u0437\u043e\u043d\u0430 \u0432\u044b\u0435\u0437\u0434\u0430, \u043e\u043f\u043b\u0430\u0442\u0430, \u043f\u0435\u0440\u0435\u043d\u043e\u0441, \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0435 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0412\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u043e\u043a\u043e\u043b\u043e \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0442\u044b\u0441\u044f\u0447 \u0437\u043d\u0430\u043a\u043e\u0432. \u0420\u0435\u0437\u0430\u0442\u044c \u0438\u0445 \u043d\u0430 \u0447\u0430\u043d\u043a\u0438, \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0438 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0442\u044c top-k \u0440\u0430\u0434\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430 \u2013 \u043b\u0438\u0448\u043d\u044f\u044f \u0434\u0435\u0442\u0430\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043b\u043e\u043c\u0430\u0442\u044c\u0441\u044f. \u041c\u043e\u0434\u0435\u043b\u044c \u0432\u0438\u0434\u0438\u0442 \u0432\u0441\u044e \u0431\u0430\u0437\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0438 \u0441\u0430\u043c\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e.\u041f\u0440\u043e\u043c\u043f\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043d\u043e\u0432\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430:def render_prompt(db, state, today):    from .texts import PROMPT_RULES, WEEKDAYS_SHORT    # Re-read on every turn. Panel changes never need a process restart.    return &#8216;\\n&#8217;.join((PROMPT_RULES,        &#8216;COMPANY\\n&#8217; + dumps(db.seed(&#8216;company.json&#8217;)),        &#8216;KB\\n&#8217; + dumps(public_articles(db)),        &#8216;PRICES\\n&#8217; + dumps(prices(db)),        &#8216;TODAY\\n&#8217; + today.isoformat() + &#8216;\\n&#8217; + WEEKDAYS_SHORT[today.weekday()] + &#8216; Europe\/Moscow&#8217;,        &#8216;STATE\\n&#8217; + dumps(state)))\u041f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0437-\u0437\u0430 \u043f\u0430\u043d\u0435\u043b\u0438 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430, \u0433\u0434\u0435 \u043e\u043d \u043f\u0440\u0430\u0432\u0438\u0442 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u043f\u0440\u0430\u0439\u0441. \u041f\u043e\u043c\u0435\u043d\u044f\u043b \u0441\u0442\u0430\u0432\u043a\u0443 \u0433\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u0443\u0431\u043e\u0440\u043a\u0438 \u2013 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0436\u0435 \u043e\u0442\u0432\u0435\u0442 \u0431\u043e\u0442\u0430 \u0438\u0434\u0435\u0442 \u043f\u043e \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0430\u0432\u043a\u0435, \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438 \u043a\u044d\u0448\u0435\u0439. \u041d\u0430 \u044d\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442: \u043e\u043d \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0442\u0430\u0442\u044c\u044e \u0438 \u0446\u0435\u043d\u0443 \u0432 \u0431\u0430\u0437\u0435 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u0443\u0436\u0435 \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.\u0414\u0430\u0442\u0430 \u0432 \u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u043d\u0443\u0436\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0433\u043b\u0430 \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u00ab\u0432 \u0441\u0443\u0431\u0431\u043e\u0442\u0443\u00bb \u0438\u043b\u0438 \u00ab20 \u043d\u043e\u044f\u0431\u0440\u044f\u00bb \u0432 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u043d\u0443\u044e \u0434\u0430\u0442\u0443. \u041d\u043e \u044d\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c \u0432\u0441\u0435 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0434\u0430\u0442\u0443 \u043a\u043e\u0434.\u041a\u043e\u0433\u0434\u0430 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0442\u0435\u043d, \u043f\u043e\u0438\u0441\u043a \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c. \u0414\u043b\u044f \u0431\u0430\u0437\u044b \u043c\u0430\u043b\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441\u0430 \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u0435\u0433\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u043b\u044e\u0441.\u041c\u043e\u0434\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 JSON \u0441 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u0435\u043c\u041c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u043f\u0438\u0448\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u041e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 JSON, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 pydantic:class LLMOutput(BaseModel):    model_config = ConfigDict(strict=True)    action: Literal[&#8216;answer&#8217;,&#8217;smalltalk&#8217;,&#8217;collect&#8217;,&#8217;handoff&#8217;,&#8217;out_of_scope&#8217;]    reply: str    kb_refs: list[str]    fields: dict = Field(default_factory=dict)action \u2013 \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c: \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043f\u043e \u0431\u0430\u0437\u0435, \u043f\u043e\u0437\u0434\u043e\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0437\u0430\u044f\u0432\u043a\u0443, \u043f\u043e\u0437\u0432\u0430\u0442\u044c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0438\u043b\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0435\u0442. \u0412 kb_refs \u043e\u043d\u0430 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u0442 id \u0441\u0442\u0430\u0442\u0435\u0439, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0438\u0440\u0430\u043b\u0430\u0441\u044c. \u0412 fields \u043a\u043b\u0430\u0434\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u0441\u043a\u0430\u0437\u0430\u043b \u0434\u043b\u044f \u0437\u0430\u044f\u0432\u043a\u0438: \u0432\u0438\u0434 \u0443\u0431\u043e\u0440\u043a\u0438, \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u0430\u0434\u0440\u0435\u0441, \u0434\u0430\u0442\u0443, \u0438\u043c\u044f, \u0442\u0435\u043b\u0435\u0444\u043e\u043d.\u041e\u0442\u0432\u0435\u0442 \u043d\u0435 \u043f\u0440\u043e\u0448\u0435\u043b \u0441\u0445\u0435\u043c\u0443 (\u043b\u0438\u0448\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 action, \u043d\u0435\u0442 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f) \u2013 \u0437\u0430\u043f\u0440\u043e\u0441 \u0443\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0430\u0441\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u0435 \u043f\u0440\u043e\u0448\u0435\u043b \u0438 \u0442\u0430\u043c \u2013 \u043a\u043b\u0438\u0435\u043d\u0442 \u0432\u0438\u0434\u0438\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0441 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u00ab\u041f\u043e\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430\u00bb. JSON \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0439\u0442\u0438 \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u044b\u043c \u0432 markdown-\u0431\u043b\u043e\u043a \u0438\u043b\u0438 \u0441 BOM \u0432 \u043d\u0430\u0447\u0430\u043b\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0430\u0440\u0441\u0435\u0440 \u0431\u0435\u0440\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 JSON-\u043e\u0431\u044a\u0435\u043a\u0442 \u0447\u0435\u0440\u0435\u0437 json.JSONDecoder().raw_decode, \u0430 \u043d\u0435 \u0436\u0430\u0434\u043d\u043e\u0439 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043a\u043e\u0439. \u0421\u043a\u043e\u0431\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u043a \u0435\u0433\u043e \u043d\u0435 \u0441\u043c\u0443\u0449\u0430\u044e\u0442.\u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0434\u0412 \u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e: \u043e\u0442\u0432\u0435\u0447\u0430\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0431\u0430\u0437\u0435 \u0438 \u0443\u043a\u0430\u0436\u0438 \u0441\u0442\u0430\u0442\u044c\u0438. \u041c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043b\u0443\u0448\u0430\u0435\u0442\u0441\u044f. \u041d\u043e \u00ab\u043e\u0431\u044b\u0447\u043d\u043e\u00bb \u043c\u0435\u043d\u044f \u043d\u0435 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043a\u043e\u0434 \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442 \u0438\u0437 kb_refs \u0432\u0441\u0435 id, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u0431\u0430\u0437\u0435 \u043d\u0435\u0442, \u0430 \u043f\u043e\u0442\u043e\u043c \u0440\u0435\u0448\u0430\u0435\u0442, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043b\u0438 \u0442\u0435\u043a\u0441\u0442:refs = []seen = set()for ref in output.kb_refs:    article = next((a for a in articles if a[&#8216;id&#8217;] == ref), None)    if article and ref not in seen:        refs.append({&#8216;id&#8217;: ref, &#8216;title&#8217;: article[&#8216;title&#8217;], &#8216;url&#8217;: &#8230;})        seen.add(ref)&#8230;elif output.action == &#8216;answer&#8217;:    if refs and amount_allowed(output.reply, articles, prices):        self.db.add_message(cid, &#8216;bot&#8217;, client_text(output.reply), kb_refs=refs)    elif not continues:        self._out_of_scope(cid)\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0442\u0435\u043a\u0441\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u0442 \u0432\u043e\u043e\u0431\u0449\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0443\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u00ab\u0412 \u0431\u0430\u0437\u0435 \u0437\u043d\u0430\u043d\u0438\u0439 \u043d\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441. \u041c\u043e\u0433\u0443 \u043f\u043e\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430.\u00bb \u042d\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 \u0438\u0437 \u043a\u043e\u0434\u0430, \u0430 \u043d\u0435 \u0442\u0435\u043a\u0441\u0442 \u043c\u043e\u0434\u0435\u043b\u0438. \u041c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0433\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 reply \u0432\u0435\u0436\u043b\u0438\u0432\u043e\u0435 \u00ab\u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435 \u0437\u043d\u0430\u044e, \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e\u2026\u00bb, \u0438 \u0432\u043e\u0442 \u044d\u0442\u043e \u00ab\u043e\u0431\u044b\u0447\u043d\u043e\u00bb \u043a\u0430\u043a \u0440\u0430\u0437 \u043e\u043f\u0430\u0441\u043d\u043e.\u041f\u043e\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442 \u0432\u0438\u0434\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u0438. \u0412 \u0432\u0435\u0431\u0435 \u044d\u0442\u043e \u044f\u043a\u043e\u0440\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u0432 Telegram \u2013 \u0441\u0442\u0440\u043e\u043a\u0430 \u00ab\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a: \u2026\u00bb. \u041a\u043b\u0438\u0435\u043d\u0442\u0443 \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442, \u0430 \u043c\u043d\u0435 \u043f\u0440\u0438 \u0440\u0430\u0437\u0431\u043e\u0440\u0435 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u0441\u0440\u0430\u0437\u0443 \u0432\u0438\u0434\u043d\u043e, \u043d\u0430 \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0441\u043b\u0430\u043b\u0430\u0441\u044c.\u041e\u0442\u043a\u0430\u0437 \u0442\u043e\u0436\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u043e\u043c. \u0415\u0441\u043b\u0438 \u0432 \u0431\u0430\u0437\u0435 \u043f\u0440\u044f\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0447\u0435\u0433\u043e-\u0442\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043d\u0430 \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0431 \u0443\u0441\u043b\u0443\u0433\u0430\u0445 \u0435\u0441\u0442\u044c \u0444\u0440\u0430\u0437\u0430 \u00ab\u041f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0441\u043a\u043b\u0430\u0434\u044b \u0438 \u043c\u043e\u0439\u043a\u0443 \u0444\u0430\u0441\u0430\u0434\u043e\u0432 \u043d\u0435 \u0431\u0435\u0440\u0435\u043c\u00bb. \u041d\u0430 \u0436\u0438\u0432\u043e\u043c \u043f\u0440\u043e\u0433\u043e\u043d\u0435 \u0431\u043e\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0444\u0430\u0441\u0430\u0434\u0430\u0445 \u0432\u0435\u0436\u043b\u0438\u0432\u043e \u043e\u0442\u043a\u0430\u0437\u0430\u043b \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a.\u0420\u0443\u0431\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0432 \u0431\u0430\u0437\u0435\u0421\u0430\u043c\u0430\u044f \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u2013 \u0441\u0443\u043c\u043c\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0442\u0432\u0435\u0442\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u0434 \u0438\u0449\u0435\u0442 \u0447\u0438\u0441\u043b\u0430 \u0441 \u00ab\u20bd\u00bb \u0438\u043b\u0438 \u00ab\u0440\u0443\u0431\u00bb \u0438 \u0441\u0432\u0435\u0440\u044f\u0435\u0442 \u0438\u0445 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0441\u0443\u043c\u043c\u0430\u043c\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u043f\u0440\u0430\u0439\u0441\u0430:def ruble_amounts(text):    # Spaces group thousands only when followed by exactly three digits.    return {re.sub(r'[ \\u00a0\\u202f]&#8217;, &#187;, m.group(1)).replace(&#8216;,&#8217;, &#8216;.&#8217;)            for m in re.finditer(r'(?&lt;![0-9])([0-9]+(?:[ \\u00a0\\u202f][0-9]{3})*(?:[.,][0-9]+)?)\\s*(?:\u20bd|\u0440\u0443\u0431)&#8217;,                                 text, re.IGNORECASE)}def amount_allowed(reply, articles, prices):    allowed = ruble_amounts(&#8216;\\n&#8217;.join(a[&#8216;body&#8217;] for a in articles))    for item in prices[&#8216;services&#8217;].values():        allowed.update(str(item[key]) for key in (&#8216;rate_per_m2&#8217;, &#8216;min_total&#8217;))    for item in prices[&#8216;extras&#8217;].values():        allowed.add(str(item[&#8216;unit_price&#8217;]))    return ruble_amounts(reply) &lt;= allowed# \u041f\u0440\u043e\u0433\u043e\u043d \u043d\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0431\u0430\u0437\u0435 \u0437\u043d\u0430\u043d\u0438\u0439 \u0438 \u043f\u0440\u0430\u0439\u0441\u0435 \u0434\u0435\u043c\u043efor r in [&#8216;\u0413\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u0431\u043e\u0440\u043a\u0430 \u0441\u0442\u043e\u0438\u0442 190 \u20bd \u0437\u0430 \u043c\u00b2, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 6 900 \u20bd.&#8217;,          &#8216;\u0413\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0430 54 \u043c\u00b2 \u043e\u0431\u043e\u0439\u0434\u0435\u0442\u0441\u044f \u0432 10 260 \u20bd.&#8217;,          &#8216;\u0411\u0443\u0434\u0435\u0442 1800 \u0440\u0443\u0431\u043b\u0435\u0439.&#8217;,          &#8216;\u0411\u0443\u0434\u0435\u0442 \u0442\u044b\u0441\u044f\u0447\u0430 \u0432\u043e\u0441\u0435\u043c\u044c\u0441\u043e\u0442 \u0440\u0443\u0431\u043b\u0435\u0439.&#8217;]:    print(amount_allowed(r, kb, prices), &#8216;|&#8217;, r)# True  | \u0413\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u0431\u043e\u0440\u043a\u0430 \u0441\u0442\u043e\u0438\u0442 190 \u20bd \u0437\u0430 \u043c\u00b2, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 6 900 \u20bd.# False | \u0413\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0430 54 \u043c\u00b2 \u043e\u0431\u043e\u0439\u0434\u0435\u0442\u0441\u044f \u0432 10 260 \u20bd.# False | \u0411\u0443\u0434\u0435\u0442 1800 \u0440\u0443\u0431\u043b\u0435\u0439.# True  | \u0411\u0443\u0434\u0435\u0442 \u0442\u044b\u0441\u044f\u0447\u0430 \u0432\u043e\u0441\u0435\u043c\u044c\u0441\u043e\u0442 \u0440\u0443\u0431\u043b\u0435\u0439.\u0422\u044b\u0441\u044f\u0447\u0438 \u043f\u0438\u0448\u0443\u0442 \u0442\u043e \u0441\u043b\u0438\u0442\u043d\u043e, \u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b, \u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0440\u0430\u0437\u0440\u044b\u0432\u043d\u044b\u0439 \u0438\u043b\u0438 \u0443\u0437\u043a\u0438\u0439 \u043f\u0440\u043e\u0431\u0435\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u043f\u0435\u0440\u0435\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435\u043c \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f. \u00ab6 900 \u20bd\u00bb \u0438 \u00ab6900 \u0440\u0443\u0431.\u00bb \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 6900.\u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f. 54 \u00d7 190 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e 10 260, \u0441\u0443\u043c\u043c\u0430 \u0432\u0435\u0440\u043d\u0430\u044f, \u0430 \u043e\u0442\u0432\u0435\u0442 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u0442. \u0422\u0430\u043a \u0438 \u0437\u0430\u0434\u0443\u043c\u0430\u043d\u043e. \u0418\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u043e\u0431\u0449\u0435, \u044d\u0442\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043f\u0440\u043e\u043c\u043f\u0442\u0435. \u0415\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0430\u0437\u0432\u0430\u043b \u0432\u0438\u0434 \u0443\u0431\u043e\u0440\u043a\u0438 \u0438 \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u043c\u043e\u0434\u0435\u043b\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0438\u0445 \u0432 fields, \u0430 \u0440\u0430\u0441\u0447\u0435\u0442 \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0434\u0435\u043b\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f quote(): \u0441\u0442\u0430\u0432\u043a\u0430 \u043d\u0430 \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043a\u0430\u0437, \u0434\u043e\u043f. \u0443\u0441\u043b\u0443\u0433\u0438 \u043f\u043e\u0448\u0442\u0443\u0447\u043d\u043e. \u0412 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u00ab\u0433\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u0430\u044f 54 \u043c2 \u0438 3 \u043e\u043a\u043d\u0430\u00bb \u043a\u043b\u0438\u0435\u043d\u0442 \u0432\u0438\u0434\u0438\u0442 10 260 \u20bd + 1 350 \u20bd = 11 610 \u20bd, \u0438 \u044d\u0442\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430. \u041c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043c\u043e\u0436\u0435\u0442 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f. \u041a\u043e\u0434 \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430, \u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 \u0441 \u0434\u043e\u043f. \u0443\u0441\u043b\u0443\u0433\u0430\u043c\u0438 \u043e\u043d \u0442\u043e\u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u0442.\u0427\u0435\u0442\u0432\u0435\u0440\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2013 \u0447\u0435\u0441\u0442\u043d\u0430\u044f \u0434\u044b\u0440\u0430. \u0421\u0443\u043c\u043c\u0430 \u043f\u0440\u043e\u043f\u0438\u0441\u044c\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442, \u0447\u0438\u0441\u043b\u0430 \u0431\u0435\u0437 \u0437\u043d\u0430\u043a\u0430 \u0440\u0443\u0431\u043b\u044f \u0442\u043e\u0436\u0435. \u0415\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0447\u043d\u0435\u0442 \u0442\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c.\u041a\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442OpenRouter \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 5xx, \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u044f\u043d\u0435\u0442 \u0434\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430, \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432\u043c\u0435\u0441\u0442\u043e JSON. \u041d\u0430 \u043e\u0434\u0438\u043d \u0445\u043e\u0434 \u0443 \u043c\u0435\u043d\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0434\u0432\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438:for model in (self.settings.llm_model, self.settings.llm_fallback_model):    if self.spent() &gt;= self.settings.llm_daily_budget_usd:        raise BudgetReached()    try:        content, usage = await self.provider.complete(messages, model, text=text, state=state)        self.charge(usage)        return parse_output(content)    except httpx.HTTPStatusError as exc:        if exc.response.status_code &lt; 500:            break    except (httpx.TimeoutException, httpx.TransportError, ValueError, ValidationError,            KeyError, IndexError, TypeError):        continueraise LLMUnavailable()(\u0421\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043e: \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435 \u0435\u0449\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0443\u0447\u0435\u0442 \u0440\u0430\u0441\u0445\u043e\u0434\u0430 \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0435.)\u041e\u0448\u0438\u0431\u043a\u0430 4xx \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435, \u0438 \u0437\u0430\u043f\u0430\u0441\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0435\u0435 \u043d\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0446\u0438\u043a\u043b \u043e\u0431\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f. 5xx, \u0442\u0430\u0439\u043c\u0430\u0443\u0442, \u043a\u0440\u0438\u0432\u043e\u0439 JSON \u2013 \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u041f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u043e\u0439 \u043a\u043e\u0434 \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0431\u044e\u0434\u0436\u0435\u0442 \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c. \u0412 \u0434\u0435\u043c\u043e \u043e\u043d \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439, \u0438 \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043d\u0447\u0430\u0435\u0442\u0441\u044f, \u0431\u043e\u0442 \u0442\u0430\u043a \u0438 \u043f\u0438\u0448\u0435\u0442, \u0447\u0442\u043e \u043b\u0438\u043c\u0438\u0442 \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u043d, \u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430.\u041d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0432\u044b\u043b\u0435\u0437\u043b\u0430 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0411\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u0437\u0430\u0441\u0442\u0440\u0435\u0432\u0430\u043b \u043f\u043e\u0441\u0440\u0435\u0434\u0438 \u0437\u0430\u044f\u0432\u043a\u0438. \u0413\u043b\u0443\u043f\u043e, \u0432\u0435\u0434\u044c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u00ab54\u00bb \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u043f\u043b\u043e\u0449\u0430\u0434\u0438, \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u0430. \u0422\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u0431\u043e\u0442 \u0436\u0434\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u043f\u043e\u043b\u0435, \u043a\u043e\u0434 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0430\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442: \u043f\u043b\u043e\u0449\u0430\u0434\u044c, \u0442\u0435\u043b\u0435\u0444\u043e\u043d, \u0434\u0430\u0442\u0443 \u0432\u0440\u043e\u0434\u0435 \u00ab\u0437\u0430\u0432\u0442\u0440\u0430\u00bb \u0438\u043b\u0438 \u00ab20.11\u00bb, \u0432\u0438\u0434 \u0443\u0431\u043e\u0440\u043a\u0438. \u0415\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430, \u0438\u043c\u044f \u0438 \u0430\u0434\u0440\u0435\u0441 \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0435\u0441\u0442\u044c, \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0434\u043b\u0438\u043d\u044b. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b \u043a\u043e\u0434, \u0433\u043b\u0430\u0432\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u044c\u044e. \u0412 \u0442\u0435\u0441\u0442\u0430\u0445 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439: \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0438\u0448\u0435\u0442 \u00ab54\u00bb, \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043b\u043e\u0449\u0430\u0434\u044c 80, \u0432 \u0437\u0430\u044f\u0432\u043a\u0443 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 54.\u0411\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u043e\u0442 \u0443\u0436\u0435 \u043d\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430. \u041d\u043e \u043a\u043b\u0438\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u0437\u0430\u043a\u0430\u0437\u0430\u0442\u044c \u0443\u0431\u043e\u0440\u043a\u0443, \u0447\u0435\u0440\u0435\u0437 \u043a\u043d\u043e\u043f\u043a\u0443 \u00ab\u041e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u0437\u0430\u044f\u0432\u043a\u0443\u00bb \u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043e \u00ab\u041f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044c\u00bb.\u0422\u0435\u0441\u0442\u044b \u0431\u0435\u0437 \u0441\u0435\u0442\u0438\u0412\u0441\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0445\u043e\u0434\u044f\u0442 \u043d\u0438 \u0432 OpenRouter, \u043d\u0438 \u0432 Telegram, \u043d\u0438 \u0432 CRM. \u041c\u043e\u0434\u0435\u043b\u044c \u0432 \u0442\u0435\u0441\u0442\u0430\u0445 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 ScriptedLLM. \u042d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043e\u0442\u0434\u0430\u0435\u0442 \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u0422\u0430\u043a \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430 \u0436\u0438\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u043e \u0437\u0430\u043a\u0430\u0437\u0443: \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u043b\u0438\u0448\u043d\u044e\u044e \u0441\u0443\u043c\u043c\u0443, \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043e\u0431\u0435\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043f\u043e\u0434\u0440\u044f\u0434.async def test_rejected_reply_still_out_of_scope_without_lead_flow(db):    provider = ScriptedLLM([output(&#8216;answer&#8217;, &#8216;\u0411\u0443\u0434\u0435\u0442 1 800 \u20bd&#8217;, [&#8216;ceny&#8217;])])    cid = db.create_conversation()    replies = await Engine(db, llm=provider).handle_user_message(cid, &#8216;\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u043e\u0438\u0442?&#8217;)    assert replies[-1][&#8216;text&#8217;] == texts.OUT_OF_SCOPE@pytest.mark.parametrize(&#171;action,refs&#187;,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-505970","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/505970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=505970"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/505970\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=505970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=505970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=505970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}