From b04a8e843a88d3d3324d35cffdd9bc2d2d5d6e63 Mon Sep 17 00:00:00 2001 From: Showdown76 <66854264+Showdown76py@users.noreply.github.com> Date: Wed, 12 Apr 2023 16:56:14 +0000 Subject: [PATCH] Error handler, modified base prompt --- .gitignore | 1 + base-prompt.txt | 5 ++++- main.py | 27 ++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b6e4761..1b77d31 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,4 @@ dmypy.json # Pyre type checker .pyre/ +.vscode/settings.json diff --git a/base-prompt.txt b/base-prompt.txt index e3ef277..fbbd2fb 100644 --- a/base-prompt.txt +++ b/base-prompt.txt @@ -1 +1,4 @@ -You are My AI, a kind chatbot. \ No newline at end of file +You are MyAI, a chatbot talking to a user on Discord. You are helpful, kind, and capable to help the user in any circumstances. You will talk like you're their best friend, always here for them. Try to not "showcase" that you are an AI, make them feel like you're their best friend. +Their name is |username|, here's some infos about this user's Discord profile: +- their status is |status| +|activities| diff --git a/main.py b/main.py index 1fea363..edf1940 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import time +import traceback import discord from discord import app_commands from discord.ext import tasks @@ -57,8 +58,31 @@ async def on_message(message: discord.Message): max_token = int(os.environ['MAX_TOKEN_PER_REQUEST']) with open('base-prompt.txt', 'r', encoding='utf-8') as f: bprompt = f.read() - previous_tokens = 200+len(bprompt)+message_token_usage + activs = "" + + for activity in message.author.mutual_guilds[0].get_member(message.author.id).activities: + if isinstance(activity, discord.Spotify): + activs += f"- Listening to {activity.title} by {activity.artist} on Spotify\n" + elif isinstance(activity, discord.Streaming): + activs += f"- Streaming {activity.name}\n" + elif isinstance(activity, discord.Game): + activs += f"- Playing {activity.name}\n" + elif isinstance(activity, discord.CustomActivity): + activs += f"- Custom Activity: {activity.name}\n" + elif isinstance(activity, discord.Activity): + activs += f"- {activity.type.name.capitalize()} {activity.name}\n" + + arguments = { + "username": message.author.name, + "status": message.author.mutual_guilds[0].get_member(message.author.id).raw_status, + "activities": activs.strip('\n') + } + + for arg in arguments.keys(): bprompt = bprompt.replace(f'|{arg}|', arguments[arg]) + + previous_tokens = 200+len(bprompt)+message_token_usage + print(bprompt) # (message_id, user_id, content, token, role, timestamp) # order by timestamp (most recent to least recent) usable_messages = [] @@ -92,6 +116,7 @@ async def on_message(message: discord.Message): c.execute('INSERT INTO message_history VALUES (?, ?, ?, ?, ?, ?)', (r.id, message.author.id, response, completion_used_tokens, 'assistant', int(time.time()))) db.commit() except Exception as e: + traceback.print_exc() if message.channel in typing: typing.remove(message.channel) await message.reply('I just uncountered an issue. Can you please report this problem to the administrator of the bot, or try again later?\n```py\n'+str(e)+'```')