From 04262a2f2e74638bd48e4680dbd7debf1c77d70b Mon Sep 17 00:00:00 2001 From: Markov Andrey Date: Tue, 30 Jun 2026 21:40:54 +0000 Subject: [PATCH] Add new file --- bots/commands/expert.py | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 bots/commands/expert.py diff --git a/bots/commands/expert.py b/bots/commands/expert.py new file mode 100644 index 0000000..1e4774a --- /dev/null +++ b/bots/commands/expert.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +""" +Экспертные команды: !summary (суммаризация документа) и !metrics (извлечение KPI). +Используют RAGClient с intent_override. +""" + +import logging +from core.commands.base import Command + +logger = logging.getLogger(__name__) + + +class SummaryCommand(Command): + name = "!summary" + aliases = ["/summary"] + + async def execute(self, msg, args: str, user_jid: str, room_jid: str = None): + """ + Суммаризация последнего загруженного документа. + Отправляет запрос на RAG-сервер с intent_override = 'SUMMARY'. + """ + try: + result = await self.bot.rag_client.query( + query=args.strip() or "Сделай суммаризацию последнего документа", + user_jid=user_jid, + room_jid=room_jid, + prompts=self.bot.prompts, + intent_override="SUMMARY", + last_file_path=None, + last_file_text=self.bot.last_file_texts.get(user_jid) + ) + answer = result.get('answer', '⚠️ Не удалось получить суммаризацию.') + reply = msg.reply(answer) + except Exception as e: + logger.exception(f"Ошибка в !summary: {e}") + reply = msg.reply(f"❌ Ошибка: {e}") + if reply: + reply.send() + + def get_help(self) -> str: + return "Суммаризация последнего документа. Использование: `!summary`" + + +class MetricsCommand(Command): + name = "!metrics" + aliases = ["/metrics"] + + async def execute(self, msg, args: str, user_jid: str, room_jid: str = None): + """ + Извлечение метрик (KPI) из базы знаний. + Отправляет запрос на RAG-сервер с intent_override = 'METRICS'. + """ + try: + result = await self.bot.rag_client.query( + query="Извлеки все KPI из документов", + user_jid=user_jid, + room_jid=room_jid, + prompts=self.bot.prompts, + intent_override="METRICS", + last_file_path=None, + last_file_text=None + ) + answer = result.get('answer', '⚠️ Не удалось извлечь метрики.') + reply = msg.reply(answer) + except Exception as e: + logger.exception(f"Ошибка в !metrics: {e}") + reply = msg.reply(f"❌ Ошибка: {e}") + if reply: + reply.send() + + def get_help(self) -> str: + return "Извлечение KPI из базы знаний. Использование: `!metrics`" \ No newline at end of file