Надо переписать код под аиограм - import logging import asyncio from telegram import…
- User
Надо переписать код под аиограм - import logging import asyncio from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.constants import ChatAction from telegram.ext import ( ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, CallbackQueryHandler, filters ) from gradio_client import Client from bs4 import BeautifulSoup import config # Импортируем конфигурационный файл
Включаем логирование
logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO )
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): await update.message.reply_text('Привет! Я бот. Задавайте ваши вопросы. Вы можете выбрать модель с помощью команды /mode')
async def mode(update: Update, context: ContextTypes.DEFAULT_TYPE): keyboard = [[ InlineKeyboardButton("o1", callback_data='o1'), InlineKeyboardButton("o1-mini", callback_data='o1-mini') ]] reply_markup = InlineKeyboardMarkup(keyboard) await update.message.reply_text('Выберите нейросеть:', reply_markup=reply_markup)
async def button_callback(update: Update, context: ContextTypes.DEFAULT_TYPE): query = update.callback_query await query.answer()
codeselection = query.data if selection == 'o1': model_name = 'yuntian-deng/o1' elif selection == 'o1-mini': model_name = 'yuntian-deng/o1mini' else: model_name = 'yuntian-deng/o1' context.user_data['model_name'] = model_name context.user_data['client'] = Client(model_name) context.user_data['chat_counter'] = 0 context.user_data['chatbot'] = [] await query.edit_message_text(text=f"Вы выбрали модель: {selection}")async def send_typing_action(update: Update, context: ContextTypes.DEFAULT_TYPE): while True: await context.bot.send_chat_action(chat_id=update.effective_chat.id, action=ChatAction.TYPING) await asyncio.sleep(2)
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): user_input = update.message.text user_data = context.user_data if 'chat_counter' not in user_data: user_data['chat_counter'] = 0 if 'chatbot' not in user_data: user_data['chatbot'] = [] if 'model_name' not in user_data: user_data['model_name'] = 'yuntian-deng/o1' if 'client' not in user_data: user_data['client'] = Client(user_data['model_name'])
code - Assistant