tui: ctrl+r to retry previous message

This commit is contained in:
Matt Low 2024-03-14 17:56:03 +00:00
parent 71833b89cd
commit 613aa1a552

View File

@ -428,6 +428,10 @@ func (m *model) handleInputKey(msg tea.KeyMsg) tea.Cmd {
return nil 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{ reply := models.Message{
Role: models.MessageRoleUser, Role: models.MessageRoleUser,
Content: userInput, Content: userInput,
@ -462,8 +466,17 @@ func (m *model) handleInputKey(msg tea.KeyMsg) tea.Cmd {
m.updateContent() m.updateContent()
m.content.GotoBottom() m.content.GotoBottom()
m.waitingForReply = true return m.promptLLM()
m.status = "Press ctrl+c to cancel" 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 m.promptLLM()
} }
return nil return nil
@ -518,6 +531,9 @@ func (m *model) generateConversationTitle() tea.Cmd {
} }
func (m *model) promptLLM() tea.Cmd { func (m *model) promptLLM() tea.Cmd {
m.waitingForReply = true
m.status = "Press ctrl+c to cancel"
return func() tea.Msg { return func() tea.Msg {
completionProvider, err := m.ctx.GetCompletionProvider(*m.ctx.Config.Defaults.Model) completionProvider, err := m.ctx.GetCompletionProvider(*m.ctx.Config.Defaults.Model)
if err != nil { if err != nil {