tui: generate titles for conversations
This commit is contained in:
parent
c14541577e
commit
387dd7534c
@ -12,6 +12,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
cmdutil "git.mlow.ca/mlow/lmcli/pkg/cmd/util"
|
||||||
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
|
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
|
||||||
models "git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
|
models "git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
|
||||||
"github.com/charmbracelet/bubbles/textarea"
|
"github.com/charmbracelet/bubbles/textarea"
|
||||||
@ -66,6 +67,8 @@ type (
|
|||||||
msgAssistantReply models.Message
|
msgAssistantReply models.Message
|
||||||
// sent when a conversation is (re)loaded
|
// sent when a conversation is (re)loaded
|
||||||
msgConversationLoaded *models.Conversation
|
msgConversationLoaded *models.Conversation
|
||||||
|
// sent when a new conversation title is set
|
||||||
|
msgConversationTitleChanged string
|
||||||
// send when a conversation's messages are laoded
|
// send when a conversation's messages are laoded
|
||||||
msgMessagesLoaded []models.Message
|
msgMessagesLoaded []models.Message
|
||||||
// sent when an error occurs
|
// sent when an error occurs
|
||||||
@ -180,12 +183,25 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.conversation.Title == "" {
|
||||||
|
cmds = append(cmds, m.generateConversationTitle())
|
||||||
|
}
|
||||||
|
|
||||||
m.updateContent()
|
m.updateContent()
|
||||||
cmds = append(cmds, m.waitForReply())
|
cmds = append(cmds, m.waitForReply())
|
||||||
case msgResponseEnd:
|
case msgResponseEnd:
|
||||||
m.replyCancelFunc = nil
|
m.replyCancelFunc = nil
|
||||||
m.waitingForReply = false
|
m.waitingForReply = false
|
||||||
m.status = "Press ctrl+s to send"
|
m.status = "Press ctrl+s to send"
|
||||||
|
case msgConversationTitleChanged:
|
||||||
|
title := string(msg)
|
||||||
|
m.conversation.Title = title
|
||||||
|
if m.persistence {
|
||||||
|
err := m.ctx.Store.SaveConversation(m.conversation)
|
||||||
|
if err != nil {
|
||||||
|
cmds = append(cmds, wrapError(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cmds) > 0 {
|
if len(cmds) > 0 {
|
||||||
@ -410,6 +426,16 @@ func (m *model) waitForChunk() tea.Cmd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *model) generateConversationTitle() tea.Cmd {
|
||||||
|
return func() tea.Msg {
|
||||||
|
title, err := cmdutil.GenerateTitle(m.ctx, m.conversation)
|
||||||
|
if err != nil {
|
||||||
|
return msgError(err)
|
||||||
|
}
|
||||||
|
return msgConversationTitleChanged(title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *model) promptLLM() tea.Cmd {
|
func (m *model) promptLLM() tea.Cmd {
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user