From 6068f398d2f69d708d1dfb923ea503dbe3674ccc Mon Sep 17 00:00:00 2001 From: chigkim Date: Thu, 29 Feb 2024 08:00:33 -0500 Subject: [PATCH] Clear last message clears last user message as well as model's response. Editing the message history does not move the history cursor to the bottom, so you can keep editing another message. Pressing esc moves history cursor to the bottom for new message. --- VOLlama.py | 21 +++++++++++++-------- changelog.md | 5 ++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/VOLlama.py b/VOLlama.py index bbbc51b..b8cc5ac 100644 --- a/VOLlama.py +++ b/VOLlama.py @@ -1,4 +1,4 @@ -version = 17 +version = 18 import wx import threading import sounddevice as sd @@ -141,13 +141,12 @@ def setStatus(self, text): self.SetStatusText(text) def clearLast(self, event): - if len(self.model.messages)==0: return - if len(self.model.messages)==1 and self.model.messages[0].role == 'system': return - if self.model.messages[-1].role == 'user': - self.prompt.SetValue(self.model.messages[-1].content) - else: + if len(self.model.messages)==0 | (len(self.model.messages)==1 and self.model.messages[0].role == 'system'): self.prompt.SetValue("") - self.model.messages = self.model.messages[:-1] + return + delete=-1 if self.model.messages[-1].role == 'user' else -2 + self.prompt.SetValue(self.model.messages[delete].content) + self.model.messages = self.model.messages[:delete] self.historyIndex = len(self.model.messages) self.refreshChat() @@ -260,6 +259,9 @@ def OnHistoryUp(self, event): self.historyIndex -= 1 if self.historyIndex<0: self.historyIndex = 0 + if self.model.messages[self.historyIndex].role == "system": + self.historyIndex = 1 + return self.prompt.SetValue(self.model.messages[self.historyIndex].content) self.prompt.SetInsertionPointEnd() self.sendButton.SetLabel("Edit") @@ -284,6 +286,10 @@ def FocusOnPrompt(self, event=None): self.model.generate = False self.speech.stop() self.prompt.SetFocus() + self.historyIndex = len(self.model.messages) + self.prompt.SetValue("") + self.sendButton.SetLabel("Send") + def onStopGeneration(self): play("receive.wav") @@ -303,7 +309,6 @@ def processMessage(message): if self.historyIndex