Fix: Working on the generate reply for discord.

Feat: Added a launch.json to allow quicker launches of the bot
docs: phoebe_model.pt will change every time we train.
This commit is contained in:
Dan
2024-05-15 22:36:38 -04:00
parent 75f1116b3b
commit fb8db8a870
3 changed files with 80 additions and 33 deletions

View File

@ -1,13 +1,39 @@
import discord
import os
from dotenv import load_dotenv
from train_gpt_model import process_message
from gpt_model import load_model
import torch
from dotenv import load_dotenv
import os
load_dotenv()
# Discord bot token
TOKEN = os.getenv("DISCORD_TOKEN")
# Load the vocabulary
with open("vocab.txt", "r", encoding="utf-8") as f:
text = f.read()
chars = sorted(list(set(text)))
# Ensure that space and other special characters are included
required_chars = " \n\r\t"
for char in required_chars:
if char not in chars:
chars.append(char)
# Add a special token for unknown characters
special_token = "<unk>"
if special_token not in chars:
chars.append(special_token)
vocab_size = len(chars)
string_to_int = {ch: i for i, ch in enumerate(chars)}
int_to_string = {i: ch for i, ch in enumerate(chars)}
# Initialize and load the model
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = load_model(vocab_size, "phoebe_model.pt").to(device)
# Initialize Discord client
intents = discord.Intents.default()
intents.message_content = True
@ -17,7 +43,6 @@ client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f"We have logged in as {client.user}")
load_model(5641, "phoebe_model.pt")
@client.event
@ -25,6 +50,9 @@ async def on_message(message):
if message.author == client.user:
return
# Debug: print the message content
print(f"Received message: '{message.content}'")
# Process the message and get a response
response = process_message(message.content)