commit 351addb9c8e76cb115bee7e437fb2aaf7c516808 Author: William Lane Date: Sun Mar 19 18:14:14 2023 -0700 mabel chat for discord diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/__pycache__/__init__.cpython-310.pyc b/app/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..2e028df Binary files /dev/null and b/app/__pycache__/__init__.cpython-310.pyc differ diff --git a/app/discord_bot/__pycache__/connect_discord.cpython-310.pyc b/app/discord_bot/__pycache__/connect_discord.cpython-310.pyc new file mode 100644 index 0000000..ff298f3 Binary files /dev/null and b/app/discord_bot/__pycache__/connect_discord.cpython-310.pyc differ diff --git a/app/discord_bot/connect_discord.py b/app/discord_bot/connect_discord.py new file mode 100644 index 0000000..dd97ad9 --- /dev/null +++ b/app/discord_bot/connect_discord.py @@ -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) diff --git a/app/mabel/__init__.py b/app/mabel/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/mabel/__pycache__/__init__.cpython-310.pyc b/app/mabel/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..b8250e0 Binary files /dev/null and b/app/mabel/__pycache__/__init__.cpython-310.pyc differ diff --git a/app/mabel/__pycache__/connect_openai.cpython-310.pyc b/app/mabel/__pycache__/connect_openai.cpython-310.pyc new file mode 100644 index 0000000..f23676f Binary files /dev/null and b/app/mabel/__pycache__/connect_openai.cpython-310.pyc differ diff --git a/app/mabel/connect_openai.py b/app/mabel/connect_openai.py new file mode 100644 index 0000000..1e3a06b --- /dev/null +++ b/app/mabel/connect_openai.py @@ -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}) \ No newline at end of file diff --git a/app/mabel/system-directives/system_directives.json b/app/mabel/system-directives/system_directives.json new file mode 100644 index 0000000..b915288 --- /dev/null +++ b/app/mabel/system-directives/system_directives.json @@ -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."} +] \ No newline at end of file diff --git a/run.py b/run.py new file mode 100644 index 0000000..51ea1d7 --- /dev/null +++ b/run.py @@ -0,0 +1,4 @@ +from app.discord_bot.connect_discord import client, discord_token + +if __name__ == '__main__': + client.run(discord_token) \ No newline at end of file