tui: ctrl+r to retry previous message

This commit is contained in:
Matt Low 2024-03-14 17:56:03 +00:00
parent 2ca94e1ffb
commit 6242ea17d8

View File

@ -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 {