From 52ad105e06566d449e3387efe4740a5d2c745367 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 15 Aug 2023 10:46:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(makeprompt.py):=20fix=20prom?= =?UTF-8?q?pt=20generation=20logic=20for=20DM=20channels=20=E2=9C=A8=20fea?= =?UTF-8?q?t(makeprompt.py):=20add=20support=20for=20generating=20prompt?= =?UTF-8?q?=20with=20server=20and=20channel=20names,=20date=20and=20time,?= =?UTF-8?q?=20and=20pretend-to-be=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/makeprompt.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/makeprompt.py b/src/makeprompt.py index ae38eea..525faa6 100644 --- a/src/makeprompt.py +++ b/src/makeprompt.py @@ -305,19 +305,30 @@ async def chat_process(self, message): 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 - - prompt = ( - prompt.replace("[prompt-prefix]", prompt_prefix) - .replace("[server-name]", message.guild.name) - .replace( - "[channel-name]", - message.channel.name - if isinstance(message.channel, discord.TextChannel) - else "DM-channel", + 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( + "[date-and-time]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S") + ) + .replace("[pretend-to-be]", pretend_to_be) ) - .replace( - "[date-and-time]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S") + else: + prompt = ( + prompt.replace("[prompt-prefix]", prompt_prefix) + .replace("[server-name]", "DM-channel") + .replace( + "[channel-name]", + "DM-channel" + ) + .replace( + "[date-and-time]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S") + ) + .replace("[pretend-to-be]", pretend_to_be) ) - .replace("[pretend-to-be]", pretend_to_be) - ) await chatgpt_process(self, messages, message, api_key, prompt, model)