yes
This commit is contained in:
parent
51e20ae01e
commit
0bc9a6ec82
5 changed files with 78 additions and 43 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,5 @@
|
||||||
.sekrit
|
.sekrit
|
||||||
__pycache__
|
__pycache__
|
||||||
|
bin/
|
||||||
|
lib/
|
||||||
|
pyvenv.cfg
|
||||||
|
|
59
lulzbot.py
59
lulzbot.py
|
@ -1,11 +1,21 @@
|
||||||
motd ='''
|
import datetime
|
||||||
_ _ ____ ___ _
|
import discord
|
||||||
| | _ _| | ___| __ ) / _ \| |_
|
from src.flan import flan_speak
|
||||||
| | | | | | | |_ / _ \| | | | __|
|
from src.cartman import cartman_speak
|
||||||
| |__| |_| | |___ / /| |_) | |_| | |_
|
from src.twitter import get_tweet
|
||||||
|_____\__,_|_____/___|____/ \___/ \__|
|
from fortune import fortune
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
motd = '''
|
||||||
|
_ _ ____ ___ _
|
||||||
|
| | _ _| | ___| __ ) / _ \| |_
|
||||||
|
| | | | | | | |_ / _ \| | | | __|
|
||||||
|
| |__| |_| | |___ / /| |_) | |_| | |_
|
||||||
|
|_____\__,_|_____/___|____/ \___/ \__|
|
||||||
'''
|
'''
|
||||||
menu ='''```
|
|
||||||
|
menu = '''```
|
||||||
Commands:
|
Commands:
|
||||||
fortune: tell a fortune
|
fortune: tell a fortune
|
||||||
chuck: give a Chuck Norris quote
|
chuck: give a Chuck Norris quote
|
||||||
|
@ -18,40 +28,41 @@ Commands:
|
||||||
Contribute!
|
Contribute!
|
||||||
https://github.com/adoyle0/lulzbot```'''
|
https://github.com/adoyle0/lulzbot```'''
|
||||||
|
|
||||||
import discord, datetime
|
|
||||||
import numpy as np
|
|
||||||
from fortune import fortune
|
|
||||||
from src.twitter import get_tweet
|
|
||||||
from src.cartman import cartman_speak
|
|
||||||
from src.flan import flan_speak
|
|
||||||
|
|
||||||
chuck_quotes = open('data/chuck_quotes').read().split('\n%\n')
|
chuck_quotes = open('data/chuck_quotes').read().split('\n%\n')
|
||||||
ligma_list = open('data/ligma_list').read().split('\n')
|
ligma_list = open('data/ligma_list').read().split('\n')
|
||||||
limericks = open('data/limericks').read().split('\n%\n')
|
limericks = open('data/limericks').read().split('\n%\n')
|
||||||
aclist = open('data/aclist').read().split('\n')
|
aclist = open('data/aclist').read().split('\n')
|
||||||
|
|
||||||
|
|
||||||
def show_menu():
|
def show_menu():
|
||||||
return menu
|
return menu
|
||||||
|
|
||||||
|
|
||||||
def musk():
|
def musk():
|
||||||
return get_tweet(44196397)
|
return get_tweet(44196397)
|
||||||
|
|
||||||
|
|
||||||
def ligma():
|
def ligma():
|
||||||
return np.random.choice(ligma_list)
|
return np.random.choice(ligma_list)
|
||||||
|
|
||||||
|
|
||||||
def limerick():
|
def limerick():
|
||||||
return np.random.choice(limericks)
|
return np.random.choice(limericks)
|
||||||
|
|
||||||
|
|
||||||
def prost():
|
def prost():
|
||||||
return 'https://tenor.com/view/prost-christoph-waltz-django-bier-zum-wohle-gif-11041516'
|
return 'https://tenor.com/view/prost-christoph-waltz-django-bier-zum-wohle-gif-11041516'
|
||||||
|
|
||||||
def chuck():
|
def chuck():
|
||||||
return np.random.choice(chuck_quotes)
|
return np.random.choice(chuck_quotes)
|
||||||
|
|
||||||
|
|
||||||
def ac():
|
def ac():
|
||||||
return np.random.choice(aclist)
|
return np.random.choice(aclist)
|
||||||
|
|
||||||
triggers = {'lulzbot': show_menu, # these need to be functions
|
|
||||||
|
triggers = {'lulzbot': show_menu, # these need to be functions
|
||||||
'musk': musk,
|
'musk': musk,
|
||||||
'deez': ligma,
|
'deez': ligma,
|
||||||
'ligma': ligma,
|
'ligma': ligma,
|
||||||
|
@ -63,18 +74,22 @@ triggers = {'lulzbot': show_menu, # these need to be functions
|
||||||
'fortune': fortune,
|
'fortune': fortune,
|
||||||
'chuck': chuck,
|
'chuck': chuck,
|
||||||
'ac': ac,
|
'ac': ac,
|
||||||
}
|
}
|
||||||
|
|
||||||
TOKEN = open('.sekrit/discord_token').read()
|
TOKEN = open('.sekrit/discord_token').read()
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
# intents.message_content = True
|
intents.message_content = True
|
||||||
client = discord.Client(activity=discord.Game(name='with myself'), intents=intents)
|
client = discord.Client(activity=discord.Game(
|
||||||
|
name='with myself'), intents=intents)
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print(motd+'\n'+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+'\nLogged in as {0.user}'.format(client))
|
print(motd+'\n'+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
|
||||||
|
'\nLogged in as {0.user}'.format(client))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_message(message):
|
async def on_message(message):
|
||||||
username = str(message.author).split('#')[0]
|
username = str(message.author).split('#')[0]
|
||||||
|
@ -87,14 +102,14 @@ async def on_message(message):
|
||||||
|
|
||||||
elif message.channel.name == 'cartman':
|
elif message.channel.name == 'cartman':
|
||||||
await message.channel.send(cartman_speak(user_message))
|
await message.channel.send(cartman_speak(user_message))
|
||||||
#await message.channel.send("I'm broken, come back later.")
|
# await message.channel.send("I'm broken, come back later.")
|
||||||
|
|
||||||
elif message.channel.name == 'flan':
|
elif message.channel.name == 'flan':
|
||||||
await message.channel.send(flan_speak(user_message))
|
await message.channel.send(flan_speak(user_message))
|
||||||
# await message.channel.send('GPU is busy, come back later')
|
# await message.channel.send('GPU is busy, come back later')
|
||||||
|
|
||||||
elif message.channel.name == 'shitposting':
|
elif message.channel.name == 'shitposting':
|
||||||
if user_message.lower() in triggers:
|
if user_message.lower() in triggers:
|
||||||
await message.channel.send(triggers[user_message.lower()]())
|
await message.channel.send(triggers[user_message.lower()]())
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
6
requirements.txt
Normal file
6
requirements.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
discord
|
||||||
|
numpy
|
||||||
|
fortune-python
|
||||||
|
tweepy
|
||||||
|
transformers
|
||||||
|
torch
|
7
run
Executable file
7
run
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source bin/activate &&
|
||||||
|
pip install --upgrade pip &&
|
||||||
|
pip install --upgrade -r requirements.txt &&
|
||||||
|
clear &&
|
||||||
|
python lulzbot.py
|
|
@ -1,36 +1,40 @@
|
||||||
|
from transformers.models.auto.modeling_auto import AutoModelForCausalLM
|
||||||
|
from transformers.models.auto.tokenization_auto import AutoTokenizer
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
url = 'https://doordesk.net/chat'
|
url = 'https://doordesk.net/chat'
|
||||||
|
|
||||||
|
|
||||||
def cartman_respond(user_message):
|
def cartman_respond(user_message):
|
||||||
message = {'Message': user_message}
|
message = {'Message': user_message}
|
||||||
response = requests.post(url,json.dumps(message))
|
response = requests.post(url, json.dumps(message))
|
||||||
return response.json().get('Cartman')
|
return response.json().get('Cartman')
|
||||||
|
|
||||||
from transformers.models.auto.modeling_auto import AutoModelForCausalLM
|
|
||||||
from transformers.models.auto.tokenization_auto import AutoTokenizer
|
|
||||||
|
|
||||||
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large")
|
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
||||||
model = AutoModelForCausalLM.from_pretrained("../cartman/train/cartman/models/output-medium")
|
model = AutoModelForCausalLM.from_pretrained(
|
||||||
|
"../cartman/train/cartman/models/output-medium-3ep")
|
||||||
|
|
||||||
|
|
||||||
def cartman_speak(input_text):
|
def cartman_speak(input_text):
|
||||||
input_ids = tokenizer(input_text + tokenizer.eos_token, return_tensors="pt").input_ids
|
input_ids = tokenizer(input_text + tokenizer.eos_token,
|
||||||
|
return_tensors="pt").input_ids
|
||||||
outputs = model.generate(
|
outputs = model.generate(
|
||||||
input_ids,
|
input_ids,
|
||||||
pad_token_id=tokenizer.eos_token_id,
|
pad_token_id=tokenizer.eos_token_id,
|
||||||
max_new_tokens = 200,
|
max_new_tokens=200,
|
||||||
num_beams = 8,
|
num_beams=8,
|
||||||
num_beam_groups = 4,
|
num_beam_groups=4,
|
||||||
no_repeat_ngram_size=3,
|
no_repeat_ngram_size=3,
|
||||||
length_penalty = 1.4,
|
length_penalty=1.4,
|
||||||
diversity_penalty = 0,
|
diversity_penalty=0,
|
||||||
repetition_penalty = 2.1,
|
repetition_penalty=2.1,
|
||||||
early_stopping = True,
|
early_stopping=True,
|
||||||
|
|
||||||
# do_sample = True,
|
# do_sample = True,
|
||||||
# top_k = 100,
|
# top_k = 100,
|
||||||
# top_p = 0.7,
|
# top_p = 0.7,
|
||||||
# temperature = 0.8,
|
# temperature = 0.8,
|
||||||
)
|
)
|
||||||
return tokenizer.decode(outputs[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
return tokenizer.decode(outputs[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
||||||
|
|
Loading…
Add table
Reference in a new issue