Add new file

This commit is contained in:
Markov Andrey
2026-06-30 21:40:54 +00:00
parent 58b9f3633a
commit 04262a2f2e

72
bots/commands/expert.py Normal file
View File

@@ -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`"