import asyncio from aiogram import Bot, Dispatcher, types from openai import AsyncOpenAI

Настройки ключей

TELEGRAM_TOKEN = "ВАШ_ТОКЕН_ОТ_BOTFATHER" OPENAI_API_KEY = "ВАШ_API_КЛЮЧ_ОТ_OPENAI"

Инициализация клиентов

bot = Bot(token=TELEGRAM_TOKEN) dp = Dispatcher() ai_client = AsyncOpenAI(api_key=OPENAI_API_KEY)

@dp.message() async def handle_message(message: types.Message): # Отправляем уведомление, что бот «печатает» await bot.send_chat_action(chat_id=message.chat.id, action="typing")

try:
    # Запрос к нейросети ChatGPT
    response = await ai_client.chat.completions.create(
        model="gpt-4o-mini", # Быстрая и экономичная модель
        messages=[
            {"role": "system", "content": "Ты дружелюбный и полезный ИИ-ассистент в Telegram."},
            {"role": "user", "content": message.text}
        ]
    )
    # Отправляем ответ пользователю
    await message.answer(response.choices[0].message.content)
    
except Exception as e:
    await message.answer("Произошла ошибка при обращении к ИИ. Попробуйте позже.")
    print(f"Ошибка: {e}")

async def main(): await dp.start_polling(bot)

if name == "main": asyncio.run(main())

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support