day2 / app.py
ffgtv3's picture
Update app.py
a678532 verified
raw
history blame
1.17 kB
import discord
from discord.ext import commands
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Настройка бота
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
# Загрузка модели и токенизатора
model_name = "Qwen/Qwen2-72B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')
@bot.command(name='AI')
async def ai_response(ctx, *, question):
# Подготовка входных данных
inputs = tokenizer.encode(question, return_tensors='pt')
# Генерация ответа
with torch.no_grad():
outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
# Декодирование и отправка ответа
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
await ctx.send(response)
# Запуск бота
bot.run('MTI3OTAxOTI4MzY1NzEzMDA4NQ.GOkPKG.LmZZLrGZdH27G70YpsOpY-uDSylhbkGdBGqX0o')