Private
Public Access
1
0

Moved api.ChatCompletionProvider, api.Chunk to api/provider

This commit is contained in:
2024-09-30 16:14:11 +00:00
parent a441866f2f
commit 327a128b2f
12 changed files with 153 additions and 152 deletions

View File

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