go-llm/llm.go

70 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"
)
2024-10-07 16:33:57 -04:00
type Image struct {
Base64 string
ContentType string
Url string
}
2024-10-06 20:01:01 -04:00
type Message struct {
2024-10-07 16:33:57 -04:00
Role Role
Name string
Text string
Images []Image
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}
}