Improve TUI system prompt handling
+ allow setting a default agent
This commit is contained in:
@@ -37,6 +37,25 @@ func (m *AppModel) ClearConversation() {
|
||||
m.RootMessages = []api.Message{}
|
||||
}
|
||||
|
||||
func (m *AppModel) ApplySystemPrompt() {
|
||||
var system string
|
||||
agent := m.Ctx.GetAgent(m.Ctx.Config.Defaults.Agent)
|
||||
if agent != nil && agent.SystemPrompt != "" {
|
||||
system = agent.SystemPrompt
|
||||
}
|
||||
if system == "" {
|
||||
system = m.Ctx.DefaultSystemPrompt()
|
||||
}
|
||||
if system != "" {
|
||||
m.Messages = api.ApplySystemPrompt(m.Messages, system, false)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *AppModel) NewConversation() {
|
||||
m.ClearConversation()
|
||||
m.ApplySystemPrompt()
|
||||
}
|
||||
|
||||
func (m *AppModel) LoadConversations() (error, []LoadedConversation) {
|
||||
messages, err := m.Ctx.Store.LatestConversationMessages()
|
||||
if err != nil {
|
||||
|
||||
@@ -38,6 +38,7 @@ func initialModel(ctx *lmcli.Context, opts LaunchOptions) *Model {
|
||||
Ctx: ctx,
|
||||
Conversation: opts.InitialConversation,
|
||||
}
|
||||
app.NewConversation()
|
||||
|
||||
m := Model{
|
||||
App: app,
|
||||
|
||||
@@ -139,17 +139,6 @@ func Chat(app *model.AppModel) *Model {
|
||||
m.replyCursor.SetChar(" ")
|
||||
m.replyCursor.Focus()
|
||||
|
||||
system := app.Ctx.DefaultSystemPrompt()
|
||||
|
||||
agent := app.Ctx.GetAgent(app.Ctx.Config.Defaults.Agent)
|
||||
if agent != nil && agent.SystemPrompt != "" {
|
||||
system = agent.SystemPrompt
|
||||
}
|
||||
|
||||
if system != "" {
|
||||
m.App.Messages = api.ApplySystemPrompt(m.App.Messages, system, false)
|
||||
}
|
||||
|
||||
m.input.Focus()
|
||||
m.input.MaxHeight = 0
|
||||
m.input.CharLimit = 0
|
||||
|
||||
@@ -53,7 +53,7 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd {
|
||||
m.updateContent()
|
||||
return shared.KeyHandled(msg)
|
||||
case "ctrl+n":
|
||||
m.App.ClearConversation()
|
||||
m.App.NewConversation()
|
||||
m.rebuildMessageCache()
|
||||
m.updateContent()
|
||||
return shared.KeyHandled(msg)
|
||||
|
||||
@@ -97,7 +97,7 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd {
|
||||
}
|
||||
return shared.KeyHandled(msg)
|
||||
case "n":
|
||||
m.App.ClearConversation()
|
||||
m.App.NewConversation()
|
||||
return shared.ChangeView(shared.ViewChat)
|
||||
case "d":
|
||||
if !m.confirmPrompt.Focused() && len(m.App.Conversations) > 0 && m.cursor < len(m.App.Conversations) {
|
||||
|
||||
Reference in New Issue
Block a user