File size: 1,173 Bytes
9e85783
 
 
a678532
9e85783
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abebc8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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')