From 62e86595b83a8e1da9a81bf8d75cb2c24eacd5ab Mon Sep 17 00:00:00 2001 From: Rene Teigen Date: Thu, 26 Jan 2023 21:23:30 +0000 Subject: [PATCH] Final redo fix, can likely remove the id parameter from encapsulate send, not used --- services/text_service.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/services/text_service.py b/services/text_service.py index 73aa79b..bbc50ac 100644 --- a/services/text_service.py +++ b/services/text_service.py @@ -182,14 +182,20 @@ class TextService: # remove duplicates from prompt_with_history and set the conversation history prompt_with_history = list(dict.fromkeys(prompt_with_history)) - converser_cog.conversation_threads[ - ctx.channel.id - ].history = prompt_with_history # Sort the prompt_with_history by increasing timestamp if pinecone is enabled if converser_cog.pinecone_service: prompt_with_history.sort(key=lambda x: x.timestamp) + # Remove the last two entries after sort, this is from the end of the list as prompt(redo), answer, prompt(original), leaving only prompt(original) and further history + if redo_request: + prompt_with_history = prompt_with_history[:-2] + + converser_cog.conversation_threads[ + ctx.channel.id + ].history = prompt_with_history + + # Ensure that the last prompt in this list is the prompt we just sent (new_prompt_item) if prompt_with_history[-1].text != new_prompt_item.text: try: @@ -301,12 +307,12 @@ class TextService: # If the user is conversing, add the GPT response to their conversation history. if ( - id in converser_cog.conversation_threads + ctx.channel.id in converser_cog.conversation_threads and not from_ask_command and not converser_cog.pinecone_service ): if not redo_request: - converser_cog.conversation_threads[id].history.append( + converser_cog.conversation_threads[ctx.channel.id].history.append( EmbeddedConversationItem( "\n" + BOT_NAME @@ -318,12 +324,12 @@ class TextService: # Embeddings case! elif ( - id in converser_cog.conversation_threads + ctx.channel.id in converser_cog.conversation_threads and not from_ask_command and not from_edit_command and converser_cog.pinecone_service ): - conversation_id = id + conversation_id = ctx.channel.id # Create an embedding and timestamp for the prompt response_text = (