|
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') |