Private
Public Access
1
0

Work to simplify model config handling

Keep a direct reference to a provider.ModelConfig in TUI's AppModel,
rather than the names of the provider and model
This commit is contained in:
2025-07-29 01:41:58 +00:00
parent 5335b5c28f
commit 0cf0a4ff0d
5 changed files with 90 additions and 90 deletions

View File

@@ -18,8 +18,7 @@ type AppModel struct {
Conversations conversation.ConversationList
Conversation conversation.Conversation
Messages []conversation.Message
Model string
ProviderName string
Model provider.ModelConfig
Provider provider.ChatCompletionProvider
Agent *lmcli.Agent
@@ -29,7 +28,6 @@ type AppModel struct {
func NewAppModel(ctx *lmcli.Context, initialConversation *conversation.Conversation) *AppModel {
app := &AppModel{
Ctx: ctx,
Model: *ctx.Config.Defaults.Model,
modifiedMessages: make(map[uint]bool),
}
@@ -39,9 +37,8 @@ func NewAppModel(ctx *lmcli.Context, initialConversation *conversation.Conversat
}
modelConfig, _ := ctx.GetModelProvider(*ctx.Config.Defaults.Model, "")
app.Model = modelConfig.Model
app.ProviderName = modelConfig.Provider
modelConfig, _ := ctx.GetDefaultModel()
app.Model = *modelConfig
app.Agent = ctx.GetAgent(ctx.Config.Defaults.Agent)
return app
}
@@ -54,7 +51,7 @@ var (
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)
return defaultStyle.Render(a.Model.Model) + accentStyle.Render("@") + defaultStyle.Render(a.Model.Provider)
}
type MessageCycleDirection int
@@ -257,13 +254,7 @@ func (a *AppModel) Prompt(
chatReplyChunks chan provider.Chunk,
stopSignal chan struct{},
) (*conversation.Message, error) {
modelConfig, err := a.Ctx.GetModelProvider(a.Model, a.ProviderName)
if err != nil {
return nil, err
}
p := modelConfig.Client
params := provider.NewRequestParameters(*modelConfig)
params := provider.NewRequestParameters(a.Model)
if a.Agent != nil {
params.Toolbox = a.Agent.Toolbox
@@ -278,14 +269,14 @@ func (a *AppModel) Prompt(
}
}()
msg, err := p.CreateChatCompletionStream(
msg, err := a.Model.Client.CreateChatCompletionStream(
ctx, params, conversation.MessagesToAPI(messages), chatReplyChunks,
)
if msg != nil {
msg := conversation.MessageFromAPI(*msg)
msg.Metadata.GenerationProvider = &a.ProviderName
msg.Metadata.GenerationModel = &a.Model
msg.Metadata.GenerationProvider = &a.Model.Provider
msg.Metadata.GenerationModel = &a.Model.Model
return &msg, err
}
return nil, err