🐛 fix(makeprompt.py): fix prompt generation logic for DM channels

 feat(makeprompt.py): add support for generating prompt with server and channel names, date and time, and pretend-to-be value
This commit is contained in:
2023-08-15 10:46:54 +02:00
parent b139e40f8a
commit 52ad105e06

View File

@@ -305,15 +305,26 @@ async def chat_process(self, message):
os.path.join(os.path.dirname(__file__), f"./prompts/{model}.txt") 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 = gpt_3_5_turbo_prompt[:] # copy the prompt but to dnot reference it
if not isinstance(message.channel, discord.DMChannel):
prompt = ( prompt = (
prompt.replace("[prompt-prefix]", prompt_prefix) prompt.replace("[prompt-prefix]", prompt_prefix)
.replace("[server-name]", message.guild.name) .replace("[server-name]", message.guild.name)
.replace( .replace(
"[channel-name]", "[channel-name]",
message.channel.name message.channel.name
if isinstance(message.channel, discord.TextChannel) )
else "DM-channel", .replace(
"[date-and-time]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S")
)
.replace("[pretend-to-be]", pretend_to_be)
)
else:
prompt = (
prompt.replace("[prompt-prefix]", prompt_prefix)
.replace("[server-name]", "DM-channel")
.replace(
"[channel-name]",
"DM-channel"
) )
.replace( .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")