2024-09-30 10:14:11 -06:00
|
|
|
package provider
|
2024-02-21 21:55:38 -07:00
|
|
|
|
2024-03-12 12:24:05 -06:00
|
|
|
import (
|
|
|
|
"context"
|
2024-09-30 10:14:11 -06:00
|
|
|
|
|
|
|
"git.mlow.ca/mlow/lmcli/pkg/api"
|
2024-03-12 12:24:05 -06:00
|
|
|
)
|
2024-02-21 21:55:38 -07:00
|
|
|
|
2024-09-30 10:14:11 -06:00
|
|
|
type ReplyCallback func(api.Message)
|
2024-03-12 14:36:24 -06:00
|
|
|
|
2024-06-08 17:37:58 -06:00
|
|
|
type Chunk struct {
|
2024-06-09 14:45:18 -06:00
|
|
|
Content string
|
|
|
|
TokenCount uint
|
2024-06-08 17:37:58 -06:00
|
|
|
}
|
|
|
|
|
2024-06-12 02:35:07 -06:00
|
|
|
type RequestParameters struct {
|
|
|
|
Model string
|
|
|
|
|
|
|
|
MaxTokens int
|
|
|
|
Temperature float32
|
|
|
|
TopP float32
|
|
|
|
|
2024-09-30 10:14:11 -06:00
|
|
|
Toolbox []api.ToolSpec
|
2024-06-12 02:35:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type ChatCompletionProvider interface {
|
2024-02-21 21:55:38 -07:00
|
|
|
// CreateChatCompletion requests a response to the provided messages.
|
|
|
|
// Replies are appended to the given replies struct, and the
|
|
|
|
// complete user-facing response is returned as a string.
|
|
|
|
CreateChatCompletion(
|
2024-03-12 12:24:05 -06:00
|
|
|
ctx context.Context,
|
2024-06-12 02:35:07 -06:00
|
|
|
params RequestParameters,
|
2024-09-30 10:14:11 -06:00
|
|
|
messages []api.Message,
|
|
|
|
) (*api.Message, error)
|
2024-02-21 21:55:38 -07:00
|
|
|
|
|
|
|
// Like CreateChageCompletion, except the response is streamed via
|
|
|
|
// the output channel as it's received.
|
|
|
|
CreateChatCompletionStream(
|
2024-03-12 12:24:05 -06:00
|
|
|
ctx context.Context,
|
2024-06-12 02:35:07 -06:00
|
|
|
params RequestParameters,
|
2024-09-30 10:14:11 -06:00
|
|
|
messages []api.Message,
|
2024-06-12 02:35:07 -06:00
|
|
|
chunks chan<- Chunk,
|
2024-09-30 10:14:11 -06:00
|
|
|
) (*api.Message, error)
|
2024-06-22 19:46:27 -06:00
|
|
|
}
|