Moved api.ChatCompletionProvider, api.Chunk to api/provider
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.mlow.ca/mlow/lmcli/pkg/api"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/api/provider"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/util"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
@@ -17,12 +18,12 @@ import (
|
||||
// Prompt prompts the configured the configured model and streams the response
|
||||
// to stdout. Returns all model reply messages.
|
||||
func Prompt(ctx *lmcli.Context, messages []api.Message, callback func(api.Message)) (*api.Message, error) {
|
||||
m, _, provider, err := ctx.GetModelProvider(*ctx.Config.Defaults.Model, "")
|
||||
m, _, p, err := ctx.GetModelProvider(*ctx.Config.Defaults.Model, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
params := api.RequestParameters{
|
||||
params := provider.RequestParameters{
|
||||
Model: m,
|
||||
MaxTokens: *ctx.Config.Defaults.MaxTokens,
|
||||
Temperature: *ctx.Config.Defaults.Temperature,
|
||||
@@ -42,13 +43,13 @@ func Prompt(ctx *lmcli.Context, messages []api.Message, callback func(api.Messag
|
||||
messages = api.ApplySystemPrompt(messages, system, false)
|
||||
}
|
||||
|
||||
content := make(chan api.Chunk)
|
||||
content := make(chan provider.Chunk)
|
||||
defer close(content)
|
||||
|
||||
// render the content received over the channel
|
||||
go ShowDelayedContent(content)
|
||||
|
||||
reply, err := provider.CreateChatCompletionStream(
|
||||
reply, err := p.CreateChatCompletionStream(
|
||||
context.Background(), params, messages, content,
|
||||
)
|
||||
|
||||
@@ -182,8 +183,8 @@ Example response:
|
||||
var msgs []msg
|
||||
for _, m := range messages {
|
||||
switch m.Role {
|
||||
case api.MessageRoleAssistant, api.MessageRoleUser:
|
||||
msgs = append(msgs, msg{string(m.Role), m.Content})
|
||||
case api.MessageRoleAssistant, api.MessageRoleUser:
|
||||
msgs = append(msgs, msg{string(m.Role), m.Content})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,19 +205,19 @@ Example response:
|
||||
},
|
||||
}
|
||||
|
||||
m, _, provider, err := ctx.GetModelProvider(
|
||||
m, _, p, err := ctx.GetModelProvider(
|
||||
*ctx.Config.Conversations.TitleGenerationModel, "",
|
||||
)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
requestParams := api.RequestParameters{
|
||||
requestParams := provider.RequestParameters{
|
||||
Model: m,
|
||||
MaxTokens: 25,
|
||||
}
|
||||
|
||||
response, err := provider.CreateChatCompletion(
|
||||
response, err := p.CreateChatCompletion(
|
||||
context.Background(), requestParams, generateRequest,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -272,7 +273,7 @@ func ShowWaitAnimation(signal chan any) {
|
||||
// chunked) content is received on the channel, the waiting animation is
|
||||
// replaced by the content.
|
||||
// Blocks until the channel is closed.
|
||||
func ShowDelayedContent(content <-chan api.Chunk) {
|
||||
func ShowDelayedContent(content <-chan provider.Chunk) {
|
||||
waitSignal := make(chan any)
|
||||
go ShowWaitAnimation(waitSignal)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user