From 351addb9c8e76cb115bee7e437fb2aaf7c516808 Mon Sep 17 00:00:00 2001 From: William Lane Date: Sun, 19 Mar 2023 18:14:14 -0700 Subject: [PATCH] mabel chat for discord --- .gitignore | 1 + app/__init__.py | 0 app/__pycache__/__init__.cpython-310.pyc | Bin 0 -> 143 bytes .../connect_discord.cpython-310.pyc | Bin 0 -> 1086 bytes app/discord_bot/connect_discord.py | 21 +++++++++++ app/mabel/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 149 bytes .../connect_openai.cpython-310.pyc | Bin 0 -> 2805 bytes app/mabel/connect_openai.py | 34 ++++++++++++++++++ .../system-directives/system_directives.json | 12 +++++++ run.py | 4 +++ 11 files changed, 72 insertions(+) create mode 100644 .gitignore create mode 100644 app/__init__.py create mode 100644 app/__pycache__/__init__.cpython-310.pyc create mode 100644 app/discord_bot/__pycache__/connect_discord.cpython-310.pyc create mode 100644 app/discord_bot/connect_discord.py create mode 100644 app/mabel/__init__.py create mode 100644 app/mabel/__pycache__/__init__.cpython-310.pyc create mode 100644 app/mabel/__pycache__/connect_openai.cpython-310.pyc create mode 100644 app/mabel/connect_openai.py create mode 100644 app/mabel/system-directives/system_directives.json create mode 100644 run.py 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 0000000000000000000000000000000000000000..2e028dff33273ea41da763e2fcebd026759d5181 GIT binary patch literal 143 zcmd1j<>g`kf|VP@Qb6=$5P=LBfgA@QE@lA|DGb33nv8xc8Hzx{2;!HKenx(7s(yJ+ zVqU6#K~a8IYH~@jer{q?YL0G7W^rpuNES{BZQFJ3MyzS(Vl#ZEutP;spDGJ4PcmMEY@A&h6 za(evnpr4uV))!)G>fb?wlNcDmnt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YypYKg?iswo2g zi%74mG49Jn%7D%K>A$3Sh>z>(uZgD?t~FfdA#Th+M!WDRc;H*_v48A8K?7ku)?nTb z!4;2sHn84h?*UqcWAAa}iFfEBr&=e^dd)WXTl;O+J`T`Ibbf3+XgE1+{3{An|Rk7cY-!;E%*Ddy_!8bZ9KxngmBbM@Bk z&+l#w`a7#@H;XpSz!Fwm?BDP2Y-|nIH^1Ci+u6Lg(JxwwLLXAJ6*f>&EUqB~)>N7y z)4|lDjdVduEH#TZdXqG>#bTIiv=??zy=&LO6`hm5$y+p1Qs3 j&UHRPIP!#FcV0Fh;I`m(pu6o5G~CndU-QrA!b0#5L0gZL literal 0 HcmV?d00001 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