From 6242ea17d85b9c7b2fb55add3dc7283d554030b6 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Thu, 14 Mar 2024 17:56:03 +0000 Subject: [PATCH] tui: ctrl+r to retry previous message --- pkg/tui/tui.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/tui/tui.go b/pkg/tui/tui.go index b95c56b..843eea6 100644 --- a/pkg/tui/tui.go +++ b/pkg/tui/tui.go @@ -428,6 +428,10 @@ func (m *model) handleInputKey(msg tea.KeyMsg) tea.Cmd { return nil } + if len(m.messages) > 0 && m.messages[len(m.messages)-1].Role == models.MessageRoleUser { + return wrapError(fmt.Errorf("Can't reply to a user message")) + } + reply := models.Message{ Role: models.MessageRoleUser, Content: userInput, @@ -462,8 +466,17 @@ func (m *model) handleInputKey(msg tea.KeyMsg) tea.Cmd { m.updateContent() m.content.GotoBottom() - m.waitingForReply = true - m.status = "Press ctrl+c to cancel" + return m.promptLLM() + case "ctrl+r": + if len(m.messages) == 0 { + return nil + } + // TODO: retry from selected message + if m.messages[len(m.messages)-1].Role != models.MessageRoleUser { + m.messages = m.messages[:len(m.messages)-1] + m.updateContent() + } + m.content.GotoBottom() return m.promptLLM() } return nil @@ -518,6 +531,9 @@ func (m *model) generateConversationTitle() tea.Cmd { } func (m *model) promptLLM() tea.Cmd { + m.waitingForReply = true + m.status = "Press ctrl+c to cancel" + return func() tea.Msg { completionProvider, err := m.ctx.GetCompletionProvider(*m.ctx.Config.Defaults.Model) if err != nil {