58 lines
844 B
Go
58 lines
844 B
Go
|
package llm
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
)
|
||
|
|
||
|
type Role string
|
||
|
|
||
|
const (
|
||
|
RoleSystem Role = "system"
|
||
|
RoleUser Role = "user"
|
||
|
RoleAssistant Role = "assistant"
|
||
|
)
|
||
|
|
||
|
type Message struct {
|
||
|
Role Role
|
||
|
Name string
|
||
|
Text string
|
||
|
}
|
||
|
|
||
|
type Request struct {
|
||
|
Messages []Message
|
||
|
Toolbox []Function
|
||
|
}
|
||
|
|
||
|
type ToolCall struct {
|
||
|
ID string
|
||
|
FunctionCall FunctionCall
|
||
|
}
|
||
|
|
||
|
type ResponseChoice struct {
|
||
|
Index int
|
||
|
Role Role
|
||
|
Content string
|
||
|
Refusal string
|
||
|
Name string
|
||
|
Calls []ToolCall
|
||
|
}
|
||
|
type Response struct {
|
||
|
Choices []ResponseChoice
|
||
|
}
|
||
|
|
||
|
type ChatCompletion interface {
|
||
|
ChatComplete(ctx context.Context, req Request) (Response, error)
|
||
|
}
|
||
|
|
||
|
type LLM interface {
|
||
|
ModelVersion(modelVersion string) (ChatCompletion, error)
|
||
|
}
|
||
|
|
||
|
func OpenAI(key string) LLM {
|
||
|
return openai{key: key}
|
||
|
}
|
||
|
|
||
|
func Anthropic(key string) LLM {
|
||
|
return anthropic{key: key}
|
||
|
}
|