Moved api.ChatCompletionProvider, api.Chunk to api/provider
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.mlow.ca/mlow/lmcli/pkg/api"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/api/provider"
|
||||
)
|
||||
|
||||
const ANTHROPIC_VERSION = "2023-06-01"
|
||||
@@ -117,7 +118,7 @@ func convertTools(tools []api.ToolSpec) []Tool {
|
||||
}
|
||||
|
||||
func createChatCompletionRequest(
|
||||
params api.RequestParameters,
|
||||
params provider.RequestParameters,
|
||||
messages []api.Message,
|
||||
) (string, ChatCompletionRequest) {
|
||||
requestMessages := make([]ChatCompletionMessage, 0, len(messages))
|
||||
@@ -188,7 +189,8 @@ func createChatCompletionRequest(
|
||||
}
|
||||
|
||||
var prefill string
|
||||
if api.IsAssistantContinuation(messages) {
|
||||
if len(messages) > 0 && messages[len(messages)-1].Role == api.MessageRoleAssistant {
|
||||
// Prompting on an assitant message, use its content as prefill
|
||||
prefill = messages[len(messages)-1].Content
|
||||
}
|
||||
|
||||
@@ -226,7 +228,7 @@ func (c *AnthropicClient) sendRequest(ctx context.Context, r ChatCompletionReque
|
||||
|
||||
func (c *AnthropicClient) CreateChatCompletion(
|
||||
ctx context.Context,
|
||||
params api.RequestParameters,
|
||||
params provider.RequestParameters,
|
||||
messages []api.Message,
|
||||
) (*api.Message, error) {
|
||||
if len(messages) == 0 {
|
||||
@@ -253,9 +255,9 @@ func (c *AnthropicClient) CreateChatCompletion(
|
||||
|
||||
func (c *AnthropicClient) CreateChatCompletionStream(
|
||||
ctx context.Context,
|
||||
params api.RequestParameters,
|
||||
params provider.RequestParameters,
|
||||
messages []api.Message,
|
||||
output chan<- api.Chunk,
|
||||
output chan<- provider.Chunk,
|
||||
) (*api.Message, error) {
|
||||
if len(messages) == 0 {
|
||||
return nil, fmt.Errorf("can't create completion from no messages")
|
||||
@@ -349,7 +351,7 @@ func (c *AnthropicClient) CreateChatCompletionStream(
|
||||
firstChunkReceived = true
|
||||
}
|
||||
block.Text += text
|
||||
output <- api.Chunk{
|
||||
output <- provider.Chunk{
|
||||
Content: text,
|
||||
TokenCount: 1,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user