Improve TUI system prompt handling

+ allow setting a default agent
This commit is contained in:
Matt Low 2024-09-23 03:00:03 +00:00
parent 676aa7b004
commit a46d211e10
6 changed files with 23 additions and 15 deletions

View File

@ -15,8 +15,7 @@ type Config struct {
Temperature *float32 `yaml:"temperature" default:"0.2"`
SystemPrompt string `yaml:"systemPrompt,omitempty"`
SystemPromptFile string `yaml:"systemPromptFile,omitempty"`
// CLI only
Agent string `yaml:"-"`
Agent string `yaml:"agent"`
} `yaml:"defaults"`
Conversations *struct {
TitleGenerationModel *string `yaml:"titleGenerationModel" default:"gpt-3.5-turbo"`

View File

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

View File

@ -38,6 +38,7 @@ func initialModel(ctx *lmcli.Context, opts LaunchOptions) *Model {
Ctx: ctx,
Conversation: opts.InitialConversation,
}
app.NewConversation()
m := Model{
App: app,

View File

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

View File

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

View File

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