50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type ReplyCallback func(Message)
|
|
|
|
type Chunk struct {
|
|
Content string
|
|
TokenCount uint
|
|
}
|
|
|
|
type RequestParameters struct {
|
|
Model string
|
|
|
|
MaxTokens int
|
|
Temperature float32
|
|
TopP float32
|
|
|
|
ToolBag []ToolSpec
|
|
}
|
|
|
|
type ChatCompletionProvider interface {
|
|
// 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(
|
|
ctx context.Context,
|
|
params RequestParameters,
|
|
messages []Message,
|
|
) (*Message, error)
|
|
|
|
// Like CreateChageCompletion, except the response is streamed via
|
|
// the output channel as it's received.
|
|
CreateChatCompletionStream(
|
|
ctx context.Context,
|
|
params RequestParameters,
|
|
messages []Message,
|
|
chunks chan<- Chunk,
|
|
) (*Message, error)
|
|
}
|
|
|
|
func IsAssistantContinuation(messages []Message) bool {
|
|
if len(messages) == 0 {
|
|
return false
|
|
}
|
|
return messages[len(messages)-1].Role == MessageRoleAssistant
|
|
}
|