From 741abc055591d6379f8ad433443ce7ed5ac10fb6 Mon Sep 17 00:00:00 2001 From: Kaveen Kumarasinghe Date: Fri, 16 Dec 2022 22:22:47 -0500 Subject: [PATCH] Close threads when end --- cogs/gpt_3_commands_and_converser.py | 26 +++++++++++++++++++++++--- models/openai_model.py | 4 ++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/cogs/gpt_3_commands_and_converser.py b/cogs/gpt_3_commands_and_converser.py index 8d7dfdd..02c4261 100644 --- a/cogs/gpt_3_commands_and_converser.py +++ b/cogs/gpt_3_commands_and_converser.py @@ -32,7 +32,7 @@ class GPT3ComCon(commands.Cog, name='GPT3ComCon'): self.DEBUG_CHANNEL = DEBUG_CHANNEL self.TEXT_CUTOFF = 1900 self.message_queue = message_queue - self.conversation_threads = defaultdict(list) + self.conversation_threads = {} @commands.Cog.listener() async def on_member_remove(self, member): @@ -42,14 +42,34 @@ class GPT3ComCon(commands.Cog, name='GPT3ComCon'): cond1= message.author.id in self.conversating_users and message.channel.name in ["gpt3", "offtopic", "general-bot", "bot"] - cond2= message.author.id in self.conversating_users and message.channel.id in self.conversation_threads[message.author.id] + cond2= message.author.id in self.conversating_users and message.author.id in self.conversation_threads \ + and message.channel.id == self.conversation_threads[message.author.id] + return cond1 or cond2 async def end_conversation(self, message): self.conversating_users.pop(message.author.id) + await message.reply( "You have ended the conversation with GPT3. Start a conversation with !g converse") + # Close all conversation threads for the user + channel = self.bot.get_channel(self.conversation_threads[message.author.id]) + # await channel.delete() TODO Schedule a delete 1 hour from now if discord's auto deletes aren't nice. + + if message.author.id in self.conversation_threads: + thread_id = self.conversation_threads[message.author.id] + self.conversation_threads.pop(message.author.id) + + # Attempt to close and lock the thread. + try: + thread = await self.bot.fetch_channel(thread_id) + await thread.edit(locked=True) + await thread.edit(name="Closed") + except: + pass + + async def send_help_text(self, message): embed = discord.Embed(title="GPT3Bot Help", description="The current commands", color=0x00ff00) embed.add_field(name="!g ", @@ -221,7 +241,7 @@ class GPT3ComCon(commands.Cog, name='GPT3ComCon'): auto_archive_duration=60) await thread.send("<@"+str(message.author.id)+"> You are now conversing with GPT3. End the conversation with !g end or just say end") - self.conversation_threads[message.author.id].append(thread.id) + self.conversation_threads[message.author.id] = thread.id return # If the prompt is just "end", end the conversation with GPT3 diff --git a/models/openai_model.py b/models/openai_model.py index 63d88c7..7ae5fb4 100644 --- a/models/openai_model.py +++ b/models/openai_model.py @@ -21,8 +21,8 @@ class Model: self._presence_penalty = 0 # Penalize new tokens based on whether they appear in the text so far self._frequency_penalty = 0 # Penalize new tokens based on their existing frequency in the text so far. (Higher frequency = lower probability of being chosen.) self._best_of = 1 # Number of responses to compare the loglikelihoods of - self._prompt_min_length = 20 - self._max_conversation_length = 5 + self._prompt_min_length = 12 + self._max_conversation_length = 12 self._model = Models.DAVINCI self._low_usage_mode = False self.usage_service = usage_service