go-llm/llm.go

64 lines
1.0 KiB
Go
Raw Normal View History

2024-10-06 21:02:26 -04:00
package go_llm
2024-10-06 20:01:01 -04:00
import (
"context"
)
type Role string
const (
RoleSystem Role = "system"
RoleUser Role = "user"
RoleAssistant Role = "assistant"
)
type Message struct {
2024-10-06 21:02:26 -04:00
Role Role
Name string
Text string
ImageBase64 string // ImageBase64 is the base64 string if the message contains an image, empty string otherwise.
2024-10-06 20:01:01 -04:00
}
type Request struct {
2024-10-06 21:02:26 -04:00
Messages []Message
Toolbox []Function
Temperature *float32
2024-10-06 20:01:01 -04:00
}
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}
}
2024-10-06 22:16:26 -04:00
func Google(key string) LLM {
return google{key: key}
}