diff --git a/src/config.py b/src/config.py index e586aae..bd3ced2 100644 --- a/src/config.py +++ b/src/config.py @@ -101,5 +101,9 @@ curs_premium.execute( """CREATE TABLE IF NOT EXISTS channels (guild_id text, channel0 text, channel1 text, channel2 text, channel3 text, channel4 text)""" ) -with open(os.path.abspath(os.path.dirname(__file__), "./prompts/gpt-3.5-turbo.txt"), "r", encoding="utf-8") as file: - gpt_3_5_turbo_prompt = file.read() \ No newline at end of file +with open( + os.path.abspath(os.path.dirname(__file__), "./prompts/gpt-3.5-turbo.txt"), + "r", + encoding="utf-8", +) as file: + gpt_3_5_turbo_prompt = file.read() diff --git a/src/makeprompt.py b/src/makeprompt.py index 63ca25b..d5c1f0b 100644 --- a/src/makeprompt.py +++ b/src/makeprompt.py @@ -29,12 +29,14 @@ async def replace_mentions(content, bot): content = content.replace(mention, f"@{user.name}") return content + def is_ignorable(content): if content.startswith("-") or content.startswith("//"): return True return False -async def fetch_messages_history(channel:discord.TextChannel, limit, original_message): + +async def fetch_messages_history(channel: discord.TextChannel, limit, original_message): messages = [] if original_message == None: async for msg in channel.history(limit=100, oldest_first=True): @@ -43,13 +45,16 @@ async def fetch_messages_history(channel:discord.TextChannel, limit, original_me if len(messages) == limit: break else: - async for msg in channel.history(limit=100, before=original_message, oldest_first=True): + async for msg in channel.history( + limit=100, before=original_message, oldest_first=True + ): if not is_ignorable(msg.content): messages.append(msg) if len(messages) == limit: break return messages + async def chatgpt_process( self, messages, message: discord.Message, api_key, prompt, model ): @@ -294,7 +299,9 @@ async def chat_process(self, message): except: pass - messages = await fetch_messages_history(message.channel, prompt_size, original_message) + messages = await fetch_messages_history( + message.channel, prompt_size, original_message + ) # if the pretend to be feature is enabled, we add the pretend to be text to the prompt if pretend_enabled: @@ -312,17 +319,15 @@ async def chat_process(self, message): prompt_path = os.path.abspath( os.path.join(os.path.dirname(__file__), f"./prompts/{model}.txt") ) - prompt = gpt_3_5_turbo_prompt[:] # copy the prompt but to dnot reference it - if not isinstance(message.channel, discord.DMChannel): + prompt = gpt_3_5_turbo_prompt[:] # copy the prompt but to dnot reference it + if not isinstance(message.channel, discord.DMChannel): prompt = ( prompt.replace("[prompt-prefix]", prompt_prefix) .replace("[server-name]", message.guild.name) + .replace("[channel-name]", message.channel.name) .replace( - "[channel-name]", - message.channel.name - ) - .replace( - "[date-and-time]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S") + "[date-and-time]", + datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S"), ) .replace("[pretend-to-be]", pretend_to_be) ) @@ -330,12 +335,10 @@ async def chat_process(self, message): prompt = ( prompt.replace("[prompt-prefix]", prompt_prefix) .replace("[server-name]", "DM-channel") + .replace("[channel-name]", "DM-channel") .replace( - "[channel-name]", - "DM-channel" - ) - .replace( - "[date-and-time]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S") + "[date-and-time]", + datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S"), ) .replace("[pretend-to-be]", pretend_to_be) )