import asyncio import telebot from telebot.types import InlineKeyboardMarkup,…
- User
import asyncio import telebot from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton from g4f.client import Client import time import requests from yandex_tts_free import YandexFreeTTS import os import shutil import logging
Настройка логирования
logging.basicConfig(level=logging.INFO) logger = logging.getLogger("my_bot_logger")
Установка event loop policy
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
bot = telebot.TeleBot("6508283219:AAEl3ORnUdHXGlyy6qlq_uVzFQ_teVVX1Wk") # Замените на ваш токен client_dict = {}
Доступные модели и голоса
MODELS = ["blackbox", "claude-3-haiku", "gpt-4o-mini", "llama-3-70b-chat"] VOICES = ["oksana", "jane"]
def create_model_selection_markup(): markup = InlineKeyboardMarkup() for model in MODELS: markup.add(InlineKeyboardButton(model, callback_data=f"model_{model}")) markup.add(InlineKeyboardButton("Назад", callback_data="back")) return markup
def create_voice_selection_markup(): markup = InlineKeyboardMarkup() for voice in VOICES: markup.add(InlineKeyboardButton(voice, callback_data=f"voice_{voice}")) markup.add(InlineKeyboardButton("Назад", callback_data="back")) return markup
def create_stop_ai_markup(): markup = InlineKeyboardMarkup() markup.add(InlineKeyboardButton("🛑 Остановить ИИ", callback_data="stop_ai")) return markup
@bot.message_handler(commands=['ai']) def send_welcome(message): bot.send_message(message.chat.id, "Выберите модель ИИ:", reply_markup=create_model_selection_markup()) if message.chat.id not in client_dict: client_dict[message.chat.id] = {'client': Client(), 'model': None, 'voice': 'oksana', 'ai_active': True}
@bot.callback_query_handler(func=lambda call: True) def handle_callback_query(call): chat_id = call.message.chat.id data = call.data.split('_')
if chat_id not in client_dict: client_dict[chat_id] = {'model': None, 'voice': None, 'ai_active': False} if data[0] == 'model': client_dict[chat_id]['model'] = data[1] bot.edit_message_text(f"Модель {data[1]} выбрана! 🎙 Выберите голос:", chat_id=chat_id, message_id=call.message.message_id, reply_markup=create_voice_selection_markup()) elif data[0] == 'voice': client_dict[chat_id]['voice'] = data[1] bot.edit_message_text("Голос выбран! Отправьте сообщение для ответа от ИИ.", chat_id=chat_id, message_id=call.message.message_id) elif data[0] == 'stop_ai': client_dict[chat_id]['ai_active'] = False bot.send_message(chat_id, "ИИ остановлен. 🛑") elif data[0] == 'back': if client_dict[chat_id]['model'] is not None: bot.edit_message_text("Выберите модель ИИ:", chat_id=chat_id, message_id=call.message.message_id, reply_markup=create_model_selection_markup()) else: bot.edit_message_text("Выберите модель ИИ:", chat_id=chat_id, message_id=call.message.message_id)@bot.message_handler(func=lambda message: True) def handle_message(message): if message.chat.id not in client_dict or not client_dict[message.chat.id].get('ai_active', False): return
- Assistant
- User
убери кнопку назад и СДЕЛАЙ ПРИ НАЖАТИИ КНОПКУ ОСТАНОВИТЬ ИИ БОТ НЕ БУДЕТ ОТВЕЧАТЬ НА СООЩЕНИЯ ПОЛЬЗОВОТЕЛЯ
- Assistant