Files
fckbot/bots/commands/expert.py
Markov Andrey 04262a2f2e Add new file
2026-06-30 21:40:54 +00:00

72 lines
2.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- 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`"