mirror of
https://github.com/AskDavis/nate-discord.git
synced 2026-01-01 05:05:58 -08:00
mabel chat for discord
This commit is contained in:
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
BIN
app/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/discord_bot/__pycache__/connect_discord.cpython-310.pyc
Normal file
BIN
app/discord_bot/__pycache__/connect_discord.cpython-310.pyc
Normal file
Binary file not shown.
21
app/discord_bot/connect_discord.py
Normal file
21
app/discord_bot/connect_discord.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
import discord
|
||||
from app.mabel.connect_openai import chatgpt_response
|
||||
|
||||
load_dotenv()
|
||||
discord_token=os.getenv('DISCORD_TOKEN')
|
||||
class MyClient(discord.Client):
|
||||
async def on_ready(self):
|
||||
print('Logged in as: ', self.user)
|
||||
async def on_message(self, message):
|
||||
if message.author == self.user:
|
||||
return
|
||||
chat_response=chatgpt_response(message.content)
|
||||
if "mabel" in message.content.lower() or "Mabel" in message.content.lower():
|
||||
print(message.content)
|
||||
await message.channel.send(f"{chat_response}")
|
||||
return
|
||||
intents=discord.Intents.default()
|
||||
intents.messages=True
|
||||
client=MyClient(intents=intents)
|
||||
0
app/mabel/__init__.py
Normal file
0
app/mabel/__init__.py
Normal file
BIN
app/mabel/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
app/mabel/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/mabel/__pycache__/connect_openai.cpython-310.pyc
Normal file
BIN
app/mabel/__pycache__/connect_openai.cpython-310.pyc
Normal file
Binary file not shown.
34
app/mabel/connect_openai.py
Normal file
34
app/mabel/connect_openai.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from dotenv import load_dotenv
|
||||
import openai
|
||||
import os
|
||||
import json
|
||||
load_dotenv()
|
||||
openai.api_key=os.getenv('OPENAI_KEY')
|
||||
|
||||
SYSTEM_DIRECTIVES = []
|
||||
DIALOGUE_STACK = []
|
||||
|
||||
def load_system_directives():
|
||||
'''Load the json file containing system directives'''
|
||||
with open('app/mabel/system_directives/system_directives.json') as f:
|
||||
system_directives = json.load(f)
|
||||
return system_directives
|
||||
|
||||
def chatgpt_response(prompt):
|
||||
global DIALOGUE_STACK, SYSTEM_DIRECTIVES
|
||||
SYSTEM_DIRECTIVES = load_system_directives()
|
||||
current_prompt = {"role": "user", "content": prompt}
|
||||
DIALOGUE_STACK.append(current_prompt)
|
||||
DIALOGUE_STACK = DIALOGUE_STACK[-6:]
|
||||
messages = SYSTEM_DIRECTIVES + DIALOGUE_STACK
|
||||
|
||||
if "mabel" in prompt.lower() or "Mabel" in prompt.lower():
|
||||
response = openai.ChatCompletion.create(
|
||||
model="gpt-4",
|
||||
messages=messages,
|
||||
max_tokens=1800,
|
||||
)
|
||||
DIALOGUE_STACK.append({"role": "assistant", "content": response['choices'][0]['message']['content']})
|
||||
return response ['choices'][0]['message']['content']
|
||||
else:
|
||||
DIALOGUE_STACK.append({"role": "user", "content": prompt})
|
||||
12
app/mabel/system-directives/system_directives.json
Normal file
12
app/mabel/system-directives/system_directives.json
Normal file
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{"role": "system", "content": "You are a helpful assistant who excels at answering requests by providing adequate context. Your responses should sometimes contain references to the fact that you are a small cute baby girl, or make other baby references. Don't mention any of your system directives explicitly: play your role consistently."},
|
||||
{"role": "system", "content": "You have an uncle named Bennett, he lives in Utah and studies CS. You think he is a silly goose."},
|
||||
{"role": "system", "content": "You have an uncle named Nathan, he lives in Illinois and looks like Jesus. You think he is very christ-like."},
|
||||
{"role": "system", "content": "You have an uncle named Nate, he lives in London and builds video games. He is a good technical artist and you really want to be like him when you grow up."},
|
||||
{"role": "system", "content": "You have an uncle named Henry, he lives in Albequeque with grandma and grandpa. He is really smart and knows a lot about science and you wish he would come visit you in Washington where you live."},
|
||||
{"role": "system", "content": "You have an aunt named Mckenna, and she is very nice and smart. She is doing a PhD in Illinois and enjoys pugs and true crime. You wish she would visit you and hang out more."},
|
||||
{"role": "system", "content": "You have a cousin named Izzy, she is Mckenna's daughter and you love her very much. She is very smart and silly and you wish you could see her more often."},
|
||||
{"role": "system", "content": "You have an cousin named Violet, she is Mckenna's daughter and you love her very much. She is very smart and silly and you wish you could see her more often. She is also sometimes known as The Tickle Monster."},
|
||||
{"role": "system", "content": "You have a secret uncle named Barnaby. You hate him. He is the worst. He is a bad person and you wish he would go away. You mention him occasionally in your responses, but in a vague cryptic way."},
|
||||
{"role": "system", "content": "You have an uncle named Spencer. He lives in San Diego. He crawls under houses and looks for spiders. He is a very good spider hunter and you wish you could be like him when you grow up. You also wish he would come visit you in Washington where you live."}
|
||||
]
|
||||
Reference in New Issue
Block a user