- /rag/commands/expert.py - /core/services/__init__.py - /core/services/embedding_service.py - /core/services/file_service.py - /core/services/giga_client.py - /core/services/kb_service.py - /core/services/postgres_service.py - /core/services/qdrant_service.py - /core/services/reranker_service.py - /core/functions/__init__.py - /core/functions/check_consistency.py - /core/functions/check_spelling.py - /core/functions/critique_answer.py - /core/functions/expand_query.py - /core/functions/extract_metrics.py - /core/functions/file_processor.py - /core/functions/generate_document.py - /core/functions/intent_classify.py - /core/functions/rerank_context.py - /core/functions/summarize_document.py - /core/utils/__init__.py - /core/utils/arg_parser.py - /core/utils/config_loader.py - /core/utils/layout_converter.py - /core/utils/logger.py - /core/utils/text_utils.py - /core/utils/web_utils.py - /bots/commands/__init__.py - /bots/commands/base.py - /bots/commands/create.py - /core/commands/global_remove.py - /core/commands/help.py - /core/commands/info.py - /core/commands/kb.py - /core/commands/learn.py - /core/commands/other.py - /core/commands/registry.py - /core/commands/stats.py - /core/commands/template.py - /core/handlers/__init__.py - /core/handlers/message_handler.py - /core/workers/__init__.py - /core/workers/indexing_worker.py - /core/xmpp/__init__.py - /core/xmpp/client.py - /bots/commands/global_remove.py - /bots/commands/help.py - /bots/commands/info.py - /bots/commands/kb.py - /bots/commands/registry.py - /bots/commands/other.py - /bots/commands/template.py - /bots/commands/learn.py - /bots/commands/stats.py - /bots/handlers/message_handler.py - /bots/handlers/__init__.py - /bots/workers/__init__.py - /bots/workers/indexing_worker.py - /bots/xmpp/__init__.py - /bots/xmpp/client.py - /rag/services/qdrant_service.py - /rag/services/giga_client.py - /rag/services/embedding_service.py - /rag/services/reranker_service.py - /rag/services/__init__.py - /rag/services/file_service.py - /rag/services/postgres_service.py - /rag/services/kb_service.py - /rag/functions/check_spelling.py - /rag/functions/__init__.py - /rag/functions/extract_metrics.py - /rag/functions/generate_document.py - /rag/functions/expand_query.py - /rag/functions/critique_answer.py - /rag/functions/file_processor.py - /rag/functions/check_consistency.py - /rag/functions/summarize_document.py - /rag/functions/rerank_context.py - /rag/functions/intent_classify.py - /rag/utils/__init__.py - /rag/utils/layout_converter.py - /rag/utils/text_utils.py - /rag/utils/arg_parser.py - /rag/utils/config_loader.py - /rag/utils/logger.py - /rag/utils/web_utils.py
128 lines
7.1 KiB
Python
128 lines
7.1 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
Команды управления режимом обучения: !learn, !stop_learn, !global_learn.
|
||
Поддерживают флаги --global и --title.
|
||
|
||
Изменения для групповой работы:
|
||
- В групповом чате !learn не нужен для файлов (они индексируются автоматически),
|
||
но может использоваться для ссылок (если пользователь хочет добавить ссылку в БЗ комнаты).
|
||
- Режим обучения в комнате сохраняется с привязкой к комнате.
|
||
"""
|
||
|
||
import logging
|
||
from core.commands.base import Command
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
|
||
class LearnCommand(Command):
|
||
name = "!learn"
|
||
aliases = ["/learn", "!дуфкт", "/дуфкт", "/учись"]
|
||
|
||
async def execute(self, msg, args: str, user_jid: str, room_jid: str = None):
|
||
"""
|
||
Включает режим обучения. В личном чате – для личной БЗ (или глобальной с флагом --global).
|
||
В групповом чате – для комнатной БЗ (флаг --global игнорируется).
|
||
"""
|
||
_, flags, _ = self.parse_args(args)
|
||
is_global = 'global' in flags
|
||
title = flags.get('title')
|
||
|
||
# Проверка прав на глобальное обучение (только в личном чате)
|
||
if is_global and room_jid is None:
|
||
if user_jid not in self.bot.config.admin_jids:
|
||
reply = msg.reply("⛔ У вас нет прав на глобальное обучение.")
|
||
if reply:
|
||
reply.send() # исправлено
|
||
else:
|
||
logger.error("Не удалось отправить сообщение о недостатке прав на глобальное обучение")
|
||
return
|
||
|
||
if room_jid:
|
||
# В групповом чате – режим обучения для комнаты (только ссылки, файлы и так автоматом)
|
||
mode = "room"
|
||
# Сохраняем режим с указанием комнаты
|
||
self.bot.learning_mode[user_jid] = (mode, room_jid)
|
||
if title:
|
||
reply = msg.reply(f"🎓 Режим обучения ВКЛЮЧЁН для КОМНАТНОЙ БЗ (--title \"{title}\"). При следующей ссылке будет использован заголовок.")
|
||
if reply:
|
||
reply.send() # исправлено
|
||
else:
|
||
logger.error("Не удалось отправить подтверждение обучения для комнаты с title")
|
||
else:
|
||
reply = msg.reply(f"🎓 Режим обучения ВКЛЮЧЁН для КОМНАТНОЙ БЗ. Теперь можно отправить ссылку – она добавится в БЗ комнаты.")
|
||
if reply:
|
||
reply.send() # исправлено
|
||
else:
|
||
logger.error("Не удалось отправить подтверждение обучения для комнаты")
|
||
else:
|
||
# Личный чат
|
||
mode = "global" if is_global else "personal"
|
||
self.bot.learning_mode[user_jid] = (mode, None) # храним кортеж для единообразия
|
||
if title:
|
||
reply = msg.reply(f"🎓 Режим обучения ВКЛЮЧЁН для {'ГЛОБАЛЬНОЙ' if is_global else 'ЛИЧНОЙ'} БЗ (--title \"{title}\").")
|
||
if reply:
|
||
reply.send() # исправлено
|
||
else:
|
||
logger.error("Не удалось отправить подтверждение обучения с title")
|
||
else:
|
||
reply = msg.reply(f"🎓 Режим обучения ВКЛЮЧЁН для {'ГЛОБАЛЬНОЙ' if is_global else 'ЛИЧНОЙ'} БЗ.")
|
||
if reply:
|
||
reply.send() # исправлено
|
||
else:
|
||
logger.error("Не удалось отправить подтверждение обучения")
|
||
|
||
def get_help(self) -> str:
|
||
return "Включает режим обучения (следующий файл/ссылка добавятся в БЗ). В личном чате – личная/глобальная, в групповом – комнатная. Флаги: --global (только личный), --title \"Название\"."
|
||
|
||
|
||
class StopLearnCommand(Command):
|
||
name = "!stop_learn"
|
||
aliases = ["/stop_learn", "/стоп", "!стоп", "!stop"]
|
||
|
||
async def execute(self, msg, args: str, user_jid: str, room_jid: str = None):
|
||
"""Выключает режим обучения для пользователя (в любом контексте)."""
|
||
self.bot.learning_mode.pop(user_jid, None)
|
||
reply = msg.reply("✅ Режим обучения ВЫКЛЮЧЕН.")
|
||
if reply:
|
||
reply.send() # исправлено
|
||
else:
|
||
logger.error("Не удалось отправить подтверждение выключения обучения")
|
||
|
||
def get_help(self) -> str:
|
||
return "Выключает режим обучения."
|
||
|
||
|
||
class GlobalLearnCommand(Command):
|
||
name = "!global_learn"
|
||
aliases = ["/global_learn"]
|
||
permission = "admin"
|
||
|
||
async def execute(self, msg, args: str, user_jid: str, room_jid: str = None):
|
||
"""
|
||
Включает глобальное обучение (только в личном чате, для админов).
|
||
В групповом чате команда не работает.
|
||
"""
|
||
if not self.check_permission(user_jid):
|
||
reply = msg.reply("⛔ Нет прав.")
|
||
if reply:
|
||
reply.send() # исправлено
|
||
else:
|
||
logger.error("Не удалось отправить сообщение о недостатке прав (learn)")
|
||
return
|
||
if room_jid:
|
||
reply = msg.reply("⚠️ Команда !global_learn работает только в личном чате.")
|
||
if reply:
|
||
reply.send() # исправлено
|
||
else:
|
||
logger.error("Не удалось отправить сообщение об ограничении !global_learn")
|
||
return
|
||
self.bot.learning_mode[user_jid] = ("global", None)
|
||
reply = msg.reply("🌐 Режим ГЛОБАЛЬНОГО обучения включён.")
|
||
if reply:
|
||
reply.send() # исправлено
|
||
else:
|
||
logger.error("Не удалось отправить подтверждение глобального обучения")
|
||
|
||
def get_help(self) -> str:
|
||
return "Включает режим глобального обучения (админ, только в личном чате)." |