Moved api.ChatCompletionProvider, api.Chunk to api/provider
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"git.mlow.ca/mlow/lmcli/pkg/agents"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/api"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/api/provider"
|
||||
cmdutil "git.mlow.ca/mlow/lmcli/pkg/cmd/util"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
@@ -24,7 +25,7 @@ type AppModel struct {
|
||||
Messages []api.Message
|
||||
Model string
|
||||
ProviderName string
|
||||
Provider api.ChatCompletionProvider
|
||||
Provider provider.ChatCompletionProvider
|
||||
}
|
||||
|
||||
func NewAppModel(ctx *lmcli.Context, initialConversation *api.Conversation) *AppModel {
|
||||
@@ -151,6 +152,28 @@ func (a *AppModel) UpdateMessageContent(message *api.Message) error {
|
||||
return a.Ctx.Store.UpdateMessage(message)
|
||||
}
|
||||
|
||||
func cycleSelectedMessage(selected *api.Message, choices []api.Message, dir MessageCycleDirection) (*api.Message, error) {
|
||||
currentIndex := -1
|
||||
for i, reply := range choices {
|
||||
if reply.ID == selected.ID {
|
||||
currentIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if currentIndex < 0 {
|
||||
return nil, fmt.Errorf("Selected message %d not found in choices, this is a bug", selected.ID)
|
||||
}
|
||||
|
||||
var next int
|
||||
if dir == CyclePrev {
|
||||
next = (currentIndex - 1 + len(choices)) % len(choices)
|
||||
} else {
|
||||
next = (currentIndex + 1) % len(choices)
|
||||
}
|
||||
return &choices[next], nil
|
||||
}
|
||||
|
||||
func (a *AppModel) CycleSelectedRoot(conv *api.Conversation, rootMessages []api.Message, dir MessageCycleDirection) (*api.Message, error) {
|
||||
if len(rootMessages) < 2 {
|
||||
return nil, nil
|
||||
@@ -225,13 +248,13 @@ func (a *AppModel) ExecuteToolCalls(toolCalls []api.ToolCall) ([]api.ToolResult,
|
||||
return agents.ExecuteToolCalls(toolCalls, agent.Toolbox)
|
||||
}
|
||||
|
||||
func (a *AppModel) PromptLLM(messages []api.Message, chatReplyChunks chan api.Chunk, stopSignal chan struct{}) (*api.Message, error) {
|
||||
model, _, provider, err := a.Ctx.GetModelProvider(a.Model, a.ProviderName)
|
||||
func (a *AppModel) PromptLLM(messages []api.Message, chatReplyChunks chan provider.Chunk, stopSignal chan struct{}) (*api.Message, error) {
|
||||
model, _, p, err := a.Ctx.GetModelProvider(a.Model, a.ProviderName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
params := api.RequestParameters{
|
||||
params := provider.RequestParameters{
|
||||
Model: model,
|
||||
MaxTokens: *a.Ctx.Config.Defaults.MaxTokens,
|
||||
Temperature: *a.Ctx.Config.Defaults.Temperature,
|
||||
@@ -251,29 +274,7 @@ func (a *AppModel) PromptLLM(messages []api.Message, chatReplyChunks chan api.Ch
|
||||
}
|
||||
}()
|
||||
|
||||
return provider.CreateChatCompletionStream(
|
||||
return p.CreateChatCompletionStream(
|
||||
ctx, params, messages, chatReplyChunks,
|
||||
)
|
||||
}
|
||||
|
||||
func cycleSelectedMessage(selected *api.Message, choices []api.Message, dir MessageCycleDirection) (*api.Message, error) {
|
||||
currentIndex := -1
|
||||
for i, reply := range choices {
|
||||
if reply.ID == selected.ID {
|
||||
currentIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if currentIndex < 0 {
|
||||
return nil, fmt.Errorf("Selected message %d not found in choices, this is a bug", selected.ID)
|
||||
}
|
||||
|
||||
var next int
|
||||
if dir == CyclePrev {
|
||||
next = (currentIndex - 1 + len(choices)) % len(choices)
|
||||
} else {
|
||||
next = (currentIndex + 1) % len(choices)
|
||||
}
|
||||
return &choices[next], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user