Private
Public Access
1
0

tui: Add setting view with support for changing the current model

This commit is contained in:
2024-09-25 15:49:45 +00:00
parent 3ec2675632
commit 69cdc0a5aa
10 changed files with 485 additions and 37 deletions

View File

@@ -8,6 +8,7 @@ import (
"git.mlow.ca/mlow/lmcli/pkg/api"
cmdutil "git.mlow.ca/mlow/lmcli/pkg/cmd/util"
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
"github.com/charmbracelet/lipgloss"
)
type LoadedConversation struct {
@@ -21,6 +22,37 @@ type AppModel struct {
Conversation *api.Conversation
RootMessages []api.Message
Messages []api.Message
Model string
ProviderName string
Provider api.ChatCompletionProvider
}
func NewAppModel(ctx *lmcli.Context, initialConversation *api.Conversation) *AppModel {
app := &AppModel{
Ctx: ctx,
Conversation: initialConversation,
Model: *ctx.Config.Defaults.Model,
}
if initialConversation == nil {
app.NewConversation()
}
model, provider, _, _ := ctx.GetModelProvider(*ctx.Config.Defaults.Model, "")
app.Model = model
app.ProviderName = provider
return app
}
var (
defaultStyle = lipgloss.NewStyle().Faint(true)
accentStyle = defaultStyle.Foreground(lipgloss.Color("6"))
)
func (a *AppModel) ActiveModel(style lipgloss.Style) string {
defaultStyle := style.Inherit(defaultStyle)
accentStyle := style.Inherit(accentStyle)
return defaultStyle.Render(a.Model) + accentStyle.Render("@") + defaultStyle.Render(a.ProviderName)
}
type MessageCycleDirection int
@@ -194,7 +226,7 @@ func (a *AppModel) ExecuteToolCalls(toolCalls []api.ToolCall) ([]api.ToolResult,
}
func (a *AppModel) PromptLLM(messages []api.Message, chatReplyChunks chan api.Chunk, stopSignal chan struct{}) (*api.Message, error) {
model, provider, err := a.Ctx.GetModelProvider(*a.Ctx.Config.Defaults.Model)
model, _, provider, err := a.Ctx.GetModelProvider(a.Model, a.ProviderName)
if err != nil {
return nil, err
}