2024-06-09 10:42:53 -06:00
|
|
|
package api
|
2024-02-21 21:55:38 -07:00
|
|
|
|
2024-03-12 12:24:05 -06:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
2024-02-21 21:55:38 -07:00
|
|
|
|
2024-06-12 02:35:07 -06:00
|
|
|
type ReplyCallback func(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
|
|
|
|
|
|
|
|
ToolBag []ToolSpec
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
messages []Message,
|
|
|
|
) (*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,
|
|
|
|
messages []Message,
|
|
|
|
chunks chan<- Chunk,
|
|
|
|
) (*Message, error)
|
2024-02-21 21:55:38 -07:00
|
|
|
}
|
2024-06-22 19:46:27 -06:00
|
|
|
|
|
|
|
func IsAssistantContinuation(messages []Message) bool {
|
|
|
|
if len(messages) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return messages[len(messages)-1].Role == MessageRoleAssistant
|
|
|
|
}
|