push of current changes
This commit is contained in:
59
llm.go
Normal file
59
llm.go
Normal file
@@ -0,0 +1,59 @@
|
||||
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}
|
||||
}
|
Reference in New Issue
Block a user