Remove: режим подтверждения (confirm/auto)
- Удалена команда /mode - Удалён ChatMode из states.py - Все запросы теперь выполняются в режиме yolo=True - Бот всегда работает в автономном режиме - Упрощён confirm_callback - только выбор модели Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
1f988ad724
commit
6b21889964
|
|
@ -14,7 +14,7 @@ from config.config import get_settings
|
||||||
from src.tools.orchestrator import Orchestrator
|
from src.tools.orchestrator import Orchestrator
|
||||||
from src.tools.xray import get_xray_client
|
from src.tools.xray import get_xray_client
|
||||||
from src.speech.speech import SpeechRecognizer
|
from src.speech.speech import SpeechRecognizer
|
||||||
from src.bot.states import chat_state, ChatMode, XRayState
|
from src.bot.states import chat_state, XRayState
|
||||||
from src.bot.config_manager import get_selected_tool, get_selected_model, set_tool
|
from src.bot.config_manager import get_selected_tool, get_selected_model, set_tool
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
|
@ -124,7 +124,6 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
"📋 Команды:\n"
|
"📋 Команды:\n"
|
||||||
"/qwen - Использовать Qwen (все запросы через Qwen)\n"
|
"/qwen - Использовать Qwen (все запросы через Qwen)\n"
|
||||||
"/open - Выбрать модель OpenCode\n"
|
"/open - Выбрать модель OpenCode\n"
|
||||||
"/mode confirm/auto - Режим подтверждения\n"
|
|
||||||
"/forget - Очистить историю\n"
|
"/forget - Очистить историю\n"
|
||||||
"/xray [email] - Добавить пользователя XRay\n"
|
"/xray [email] - Добавить пользователя XRay\n"
|
||||||
"/stt on|off - Распознавание речи\n\n"
|
"/stt on|off - Распознавание речи\n\n"
|
||||||
|
|
@ -135,31 +134,13 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
await update.message.reply_text(help_text)
|
await update.message.reply_text(help_text)
|
||||||
|
|
||||||
|
|
||||||
async def mode_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
||||||
if not context.args:
|
|
||||||
mode = chat_state.get_mode(update.effective_chat.id)
|
|
||||||
mode_name = "с подтверждением" if mode == ChatMode.CONFIRM else "автономный"
|
|
||||||
await update.message.reply_text(f"Текущий режим: {mode_name}")
|
|
||||||
return
|
|
||||||
|
|
||||||
mode_arg = context.args[0].lower()
|
|
||||||
if mode_arg == "confirm":
|
|
||||||
chat_state.set_mode(update.effective_chat.id, ChatMode.CONFIRM)
|
|
||||||
await update.message.reply_text("Режим: подтверждение для опасных действий")
|
|
||||||
elif mode_arg == "auto":
|
|
||||||
chat_state.set_mode(update.effective_chat.id, ChatMode.AUTO)
|
|
||||||
await update.message.reply_text("Режим: автономный")
|
|
||||||
else:
|
|
||||||
await update.message.reply_text("Использование: /mode confirm | auto")
|
|
||||||
|
|
||||||
|
|
||||||
async def confirm_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def confirm_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
await query.answer()
|
await query.answer()
|
||||||
|
|
||||||
chat_id = query.message.chat.id
|
chat_id = query.message.chat.id
|
||||||
data = query.data
|
data = query.data
|
||||||
|
|
||||||
if data.startswith("model_"):
|
if data.startswith("model_"):
|
||||||
model_name = data.replace("model_", "")
|
model_name = data.replace("model_", "")
|
||||||
if not model_name.startswith("opencode/"):
|
if not model_name.startswith("opencode/"):
|
||||||
|
|
@ -169,41 +150,6 @@ async def confirm_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
set_tool("opencode", model)
|
set_tool("opencode", model)
|
||||||
await query.edit_message_text(f"✅ Выбрана модель: {model}\nВсе запросы будут идти через эту модель.")
|
await query.edit_message_text(f"✅ Выбрана модель: {model}\nВсе запросы будут идти через эту модель.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if data == "confirm_yes":
|
|
||||||
pending = chat_state.get_pending_action(chat_id)
|
|
||||||
if not pending:
|
|
||||||
await query.edit_message_text("❌ Ошибка: действие не найдено")
|
|
||||||
return
|
|
||||||
|
|
||||||
await query.edit_message_text("✅ Подтверждено. Выполняю...")
|
|
||||||
prompt = pending.get("prompt")
|
|
||||||
tool = pending.get("tool")
|
|
||||||
dangerous = pending.get("dangerous", False)
|
|
||||||
chat_state.set_waiting_confirmation(chat_id, False)
|
|
||||||
|
|
||||||
model_raw = get_selected_model()
|
|
||||||
model = None
|
|
||||||
if tool == "opencode" and model_raw:
|
|
||||||
if model_raw.startswith("opencode/"):
|
|
||||||
model = model_raw.replace("opencode/", "", 1)
|
|
||||||
else:
|
|
||||||
model = model_raw
|
|
||||||
|
|
||||||
thinking_msg = await query.message.reply_text("🤔 Думаю...")
|
|
||||||
|
|
||||||
simple_prompt = prompt
|
|
||||||
result, success = await orchestrator.ask(simple_prompt, chat_id, tool, model, yolo=True)
|
|
||||||
|
|
||||||
text = result[:4096] if len(result) > 4096 else result
|
|
||||||
await query.message.reply_text(text, parse_mode="Markdown")
|
|
||||||
try:
|
|
||||||
await thinking_msg.delete()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
elif data == "confirm_no":
|
|
||||||
chat_state.set_waiting_confirmation(chat_id, False)
|
|
||||||
await query.edit_message_text("❌ Отменено. Команда не будет выполнена.")
|
|
||||||
|
|
||||||
|
|
||||||
async def execute_tool_query(update, tool: str, prompt: str):
|
async def execute_tool_query(update, tool: str, prompt: str):
|
||||||
|
|
@ -223,7 +169,7 @@ async def execute_tool_query(update, tool: str, prompt: str):
|
||||||
|
|
||||||
async def qwen_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def qwen_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
set_tool("qwen", None)
|
set_tool("qwen", None)
|
||||||
|
|
||||||
if not context.args:
|
if not context.args:
|
||||||
await update.message.reply_text(
|
await update.message.reply_text(
|
||||||
"✅ Теперь все запросы будут отправляться в Qwen.\n"
|
"✅ Теперь все запросы будут отправляться в Qwen.\n"
|
||||||
|
|
@ -231,14 +177,12 @@ async def qwen_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
"Пример: /qwen Привет, как дела?"
|
"Пример: /qwen Привет, как дела?"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
prompt = " ".join(context.args)
|
prompt = " ".join(context.args)
|
||||||
chat_id = update.effective_chat.id
|
chat_id = update.effective_chat.id
|
||||||
mode = chat_state.get_mode(chat_id)
|
|
||||||
use_yolo = mode == ChatMode.AUTO
|
thinking_msg = await update.message.reply_text("🤔 Думаю...")
|
||||||
|
result, success = await orchestrator.ask(prompt, chat_id, "qwen", None, yolo=True)
|
||||||
thinking_msg = await update.message.reply_text("🤔 Думаю..." + (" (YOLO)" if use_yolo else ""))
|
|
||||||
result, success = await orchestrator.ask(prompt, chat_id, "qwen", None, yolo=use_yolo)
|
|
||||||
text = result[:4096] if len(result) > 4096 else result
|
text = result[:4096] if len(result) > 4096 else result
|
||||||
await update.message.reply_text(text)
|
await update.message.reply_text(text)
|
||||||
try:
|
try:
|
||||||
|
|
@ -268,24 +212,22 @@ async def open_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
if not context.args:
|
if not context.args:
|
||||||
await open_menu(update, context)
|
await open_menu(update, context)
|
||||||
return
|
return
|
||||||
|
|
||||||
prompt = " ".join(context.args)
|
prompt = " ".join(context.args)
|
||||||
tool = get_selected_tool()
|
tool = get_selected_tool()
|
||||||
model = get_selected_model()
|
model = get_selected_model()
|
||||||
|
|
||||||
if tool != "opencode":
|
if tool != "opencode":
|
||||||
set_tool("opencode", "opencode/minimax-m2.5-free")
|
set_tool("opencode", "opencode/minimax-m2.5-free")
|
||||||
model = "opencode/minimax-m2.5-free"
|
model = "opencode/minimax-m2.5-free"
|
||||||
|
|
||||||
if not model:
|
if not model:
|
||||||
model = "opencode/minimax-m2.5-free"
|
model = "opencode/minimax-m2.5-free"
|
||||||
|
|
||||||
chat_id = update.effective_chat.id
|
chat_id = update.effective_chat.id
|
||||||
mode = chat_state.get_mode(chat_id)
|
|
||||||
use_yolo = mode == ChatMode.AUTO
|
thinking_msg = await update.message.reply_text("🤔 Думаю...")
|
||||||
|
result, success = await orchestrator.ask(prompt, chat_id, "opencode", model, yolo=True)
|
||||||
thinking_msg = await update.message.reply_text("🤔 Думаю..." + (" (YOLO)" if use_yolo else ""))
|
|
||||||
result, success = await orchestrator.ask(prompt, chat_id, "opencode", model, yolo=use_yolo)
|
|
||||||
text = result[:4096] if len(result) > 4096 else result
|
text = result[:4096] if len(result) > 4096 else result
|
||||||
await update.message.reply_text(text)
|
await update.message.reply_text(text)
|
||||||
try:
|
try:
|
||||||
|
|
@ -552,7 +494,6 @@ def main():
|
||||||
|
|
||||||
application.add_handler(CommandHandler("start", start))
|
application.add_handler(CommandHandler("start", start))
|
||||||
application.add_handler(CommandHandler("help", help_command))
|
application.add_handler(CommandHandler("help", help_command))
|
||||||
application.add_handler(CommandHandler("mode", mode_command))
|
|
||||||
application.add_handler(CommandHandler("qwen", qwen_command))
|
application.add_handler(CommandHandler("qwen", qwen_command))
|
||||||
application.add_handler(CommandHandler("open", open_command))
|
application.add_handler(CommandHandler("open", open_command))
|
||||||
application.add_handler(CommandHandler("forget", forget_command))
|
application.add_handler(CommandHandler("forget", forget_command))
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,6 @@ from enum import Enum
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ChatMode(str, Enum):
|
|
||||||
CONFIRM = "confirm"
|
|
||||||
AUTO = "auto"
|
|
||||||
|
|
||||||
|
|
||||||
class XRayState(str, Enum):
|
class XRayState(str, Enum):
|
||||||
"""Состояния для команды /xray"""
|
"""Состояния для команды /xray"""
|
||||||
WAITING_EMAIL = "waiting_email"
|
WAITING_EMAIL = "waiting_email"
|
||||||
|
|
@ -19,37 +14,6 @@ class ChatState:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.states: Dict[int, dict] = {}
|
self.states: Dict[int, dict] = {}
|
||||||
|
|
||||||
def get_mode(self, chat_id: int) -> ChatMode:
|
|
||||||
return self.states.get(chat_id, {}).get("mode", ChatMode.CONFIRM)
|
|
||||||
|
|
||||||
def set_mode(self, chat_id: int, mode: ChatMode):
|
|
||||||
if chat_id not in self.states:
|
|
||||||
self.states[chat_id] = {}
|
|
||||||
self.states[chat_id]["mode"] = mode
|
|
||||||
|
|
||||||
def is_waiting_confirmation(self, chat_id: int) -> bool:
|
|
||||||
return self.states.get(chat_id, {}).get("waiting_confirmation", False)
|
|
||||||
|
|
||||||
def set_waiting_confirmation(self, chat_id: int, waiting: bool, action_data: Optional[dict] = None):
|
|
||||||
if chat_id not in self.states:
|
|
||||||
self.states[chat_id] = {}
|
|
||||||
self.states[chat_id]["waiting_confirmation"] = waiting
|
|
||||||
if action_data:
|
|
||||||
self.states[chat_id]["pending_action"] = action_data
|
|
||||||
elif not waiting:
|
|
||||||
self.states[chat_id].pop("pending_action", None)
|
|
||||||
|
|
||||||
def get_pending_action(self, chat_id: int) -> Optional[dict]:
|
|
||||||
return self.states.get(chat_id, {}).get("pending_action")
|
|
||||||
|
|
||||||
def set_current_task(self, chat_id: int, task_id: Optional[str]):
|
|
||||||
if chat_id not in self.states:
|
|
||||||
self.states[chat_id] = {}
|
|
||||||
self.states[chat_id]["current_task"] = task_id
|
|
||||||
|
|
||||||
def get_current_task(self, chat_id: int) -> Optional[str]:
|
|
||||||
return self.states.get(chat_id, {}).get("current_task")
|
|
||||||
|
|
||||||
# Методы для состояния XRay
|
# Методы для состояния XRay
|
||||||
def set_xray_state(self, chat_id: int, state: Optional[XRayState]):
|
def set_xray_state(self, chat_id: int, state: Optional[XRayState]):
|
||||||
if chat_id not in self.states:
|
if chat_id not in self.states:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue