go-llm/llm.go

70 lines
1.0 KiB
Go

package go_llm
import (
"context"
)
type Role string
const (
RoleSystem Role = "system"
RoleUser Role = "user"
RoleAssistant Role = "assistant"
)
type Image struct {
Base64 string
ContentType string
Url string
}
type Message struct {
Role Role
Name string
Text string
Images []Image
}
type Request struct {
Messages []Message
Toolbox *ToolBox
Temperature *float32
}
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 openaiImpl{key: key}
}
func Anthropic(key string) LLM {
return anthropic{key: key}
}
func Google(key string) LLM {
return google{key: key}
}