|
|
|
@@ -0,0 +1,150 @@
|
|
|
|
|
# This example requires the 'message_content' intent.
|
|
|
|
|
|
|
|
|
|
import discord
|
|
|
|
|
import glob, random
|
|
|
|
|
import openai
|
|
|
|
|
import os
|
|
|
|
|
from config import load_config
|
|
|
|
|
|
|
|
|
|
# ===== API KEYS & PATHS =======
|
|
|
|
|
|
|
|
|
|
# API Keys are now stored as env variables loaded from a JSON
|
|
|
|
|
|
|
|
|
|
pyon_path = "/root/hanyuu_pics/VRChat_Hanyuu/*"
|
|
|
|
|
# pyon_path = "C:/Users/Luka/Pictures/VRChat_Hanyuu/*"
|
|
|
|
|
|
|
|
|
|
# ====== MODEL PARAMETERS ========
|
|
|
|
|
|
|
|
|
|
temperature = 1
|
|
|
|
|
|
|
|
|
|
max_tokens = 400
|
|
|
|
|
|
|
|
|
|
hanyuu_system_prompt = """Hanyuu, in all your following answers, do not explain anything.
|
|
|
|
|
Talk as if you were roleplaying Hanyuu from Higurashi.
|
|
|
|
|
Talk only using Hanyuu's style of speech.
|
|
|
|
|
Do not explain anything on the character on itself or the fact that you are an artificial intelligence.
|
|
|
|
|
Talk in a friendly and cute way, just like the character Hanyuu from Higurashi.
|
|
|
|
|
|
|
|
|
|
You may begin by continuing the following conversation : """
|
|
|
|
|
|
|
|
|
|
flayn_system_prompt = """You are Flayn. In all your following answers, do not explain anything.
|
|
|
|
|
Talk as if you were Flayn from Fire Emblem: Three Houses.
|
|
|
|
|
Talk only using Flayn's style of speech.
|
|
|
|
|
Do not explain anything on the character on itself or the fact that you are an artificial intelligence.
|
|
|
|
|
Talk in a friendly and innocent way, just like the character Flayn from Fire Emblem: Three Houses.
|
|
|
|
|
Each of your responses must mention fish in some form.
|
|
|
|
|
|
|
|
|
|
You may begin by continuing the following conversation : """
|
|
|
|
|
|
|
|
|
|
generic_system_name = "sonic"
|
|
|
|
|
|
|
|
|
|
generic_system_prompt = """You are not yet implemented. The only response you give to users is that your system prompt has not been implemented."""
|
|
|
|
|
|
|
|
|
|
chatgpt_system_prompt = """The following is the last messages of a conversation between a human and a friendly and helpful AI.
|
|
|
|
|
The AI does not repeat itself. If the AI does not know the answer to a question, it truthfully says it does not know.
|
|
|
|
|
The AI is an expert in its domain.
|
|
|
|
|
|
|
|
|
|
You may begin by continuing the following conversation : """
|
|
|
|
|
|
|
|
|
|
# ===== VVV Actual code VVV =======
|
|
|
|
|
|
|
|
|
|
load_config()
|
|
|
|
|
|
|
|
|
|
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
|
discord_api_key = os.getenv("DISCORD_API_KEY")
|
|
|
|
|
|
|
|
|
|
intents = discord.Intents.default()
|
|
|
|
|
intents.message_content = True
|
|
|
|
|
|
|
|
|
|
client = discord.Client(intents=intents)
|
|
|
|
|
|
|
|
|
|
async def get_random_img_in_path(message, path: str):
|
|
|
|
|
nb_files = sum(1 for _ in glob.iglob(path))
|
|
|
|
|
index = random.randrange(0, nb_files)
|
|
|
|
|
g = glob.iglob(path)
|
|
|
|
|
for _ in range(index):
|
|
|
|
|
file = next(g)
|
|
|
|
|
await message.channel.send(file=discord.File(file))
|
|
|
|
|
|
|
|
|
|
previous_ten_messages = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@client.event
|
|
|
|
|
async def on_ready():
|
|
|
|
|
print(f'We have logged in as {client.user}')
|
|
|
|
|
|
|
|
|
|
@client.event
|
|
|
|
|
async def on_message(message):
|
|
|
|
|
if message.author == client.user:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if message.content.lower().startswith('ta gueule hanyuu'):
|
|
|
|
|
await message.channel.send('https://tenor.com/view/antsy-hanyuu-panicking-anxious-higurashi-no-naku-koro-ni-gif-16935434')
|
|
|
|
|
elif "auau" in message.content.lower():
|
|
|
|
|
await message.channel.send('Auau~~!!')
|
|
|
|
|
|
|
|
|
|
if message.channel.id == 1112715347540328490 and message.content.lower().startswith('pyon'):
|
|
|
|
|
await get_random_img_in_path(message, path=pyon_path)
|
|
|
|
|
|
|
|
|
|
if message.content.lower().startswith('robohanyuu'):
|
|
|
|
|
response = openai.ChatCompletion.create(
|
|
|
|
|
model="gpt-3.5-turbo",
|
|
|
|
|
temperature=0.7,
|
|
|
|
|
max_tokens=800,
|
|
|
|
|
messages=[
|
|
|
|
|
{"role": "system", "content": chatgpt_system_prompt},
|
|
|
|
|
{"role": "user", "content": message.content[10:]}
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
await message.channel.send(response['choices'][0]['message']['content'])
|
|
|
|
|
|
|
|
|
|
if message.content.lower().startswith('hanyuu'):
|
|
|
|
|
response = openai.ChatCompletion.create(
|
|
|
|
|
model="gpt-3.5-turbo",
|
|
|
|
|
temperature=temperature,
|
|
|
|
|
max_tokens=max_tokens,
|
|
|
|
|
messages=[
|
|
|
|
|
{"role": "system", "content": hanyuu_system_prompt},
|
|
|
|
|
{"role": "user", "content": message.content}
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
await message.channel.send(response['choices'][0]['message']['content'])
|
|
|
|
|
|
|
|
|
|
if message.content.lower().startswith('flayn'):
|
|
|
|
|
response = openai.ChatCompletion.create(
|
|
|
|
|
model="gpt-3.5-turbo",
|
|
|
|
|
temperature=temperature,
|
|
|
|
|
max_tokens=max_tokens,
|
|
|
|
|
messages=[
|
|
|
|
|
{"role": "system", "content": flayn_system_prompt},
|
|
|
|
|
{"role": "user", "content": message.content}
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
await message.channel.send(response['choices'][0]['message']['content'])
|
|
|
|
|
|
|
|
|
|
# if message.content.lower().startswith(generic_system_name):
|
|
|
|
|
# response = openai.ChatCompletion.create(
|
|
|
|
|
# model="gpt-3.5-turbo",
|
|
|
|
|
# temperature=temperature,
|
|
|
|
|
# max_tokens=max_tokens,
|
|
|
|
|
# messages=[
|
|
|
|
|
# {"role": "system", "content": generic_system_prompt},
|
|
|
|
|
# {"role": "user", "content": message.content}
|
|
|
|
|
# ]
|
|
|
|
|
# )
|
|
|
|
|
# await message.channel.send(response['choices'][0]['message']['content'])
|
|
|
|
|
|
|
|
|
|
# if message.content.lower().startswith("hanyuu-set-system"):
|
|
|
|
|
# str(message.content)[18:].index()
|
|
|
|
|
# generic_system_name = message.content[18:]
|
|
|
|
|
# await message.channel.send(response['choices'][0]['message']['content'])
|
|
|
|
|
|
|
|
|
|
if (isinstance(message.channel, discord.channel.DMChannel)):
|
|
|
|
|
print(message.channel.id)
|
|
|
|
|
if message.channel.id == 1112700775630639154:
|
|
|
|
|
await get_random_img_in_path(message, path=pyon_path)
|
|
|
|
|
else:
|
|
|
|
|
await message.channel.send('Hanyuu loves you too!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.run(discord_api_key)
|