go-llm/llm.go

60 lines
1010 B
Go

package go_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
ImageBase64 string // ImageBase64 is the base64 string if the message contains an image, empty string otherwise.
}
type Request struct {
Messages []Message
Toolbox []Function
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 openai{key: key}
}
func Anthropic(key string) LLM {
return anthropic{key: key}
}