55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
// Package llm defines the provider abstraction and message types.
|
|
package llm
|
|
|
|
import "context"
|
|
|
|
type Role string
|
|
|
|
const (
|
|
RoleSystem Role = "system"
|
|
RoleUser Role = "user"
|
|
RoleAssistant Role = "assistant"
|
|
RoleTool Role = "tool"
|
|
)
|
|
|
|
type ToolCall struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Arguments string `json:"arguments"` // raw JSON
|
|
}
|
|
|
|
type Message struct {
|
|
Role Role `json:"role"`
|
|
Content string `json:"content"`
|
|
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
|
ToolCallID string `json:"tool_call_id,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
// Cancelled marks a partial assistant answer that was stopped by the user.
|
|
Cancelled bool `json:"cancelled,omitempty"`
|
|
}
|
|
|
|
// ToolSpec describes a callable tool using JSON Schema parameters.
|
|
type ToolSpec struct {
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Parameters map[string]any `json:"parameters"`
|
|
}
|
|
|
|
type Request struct {
|
|
Messages []Message
|
|
Tools []ToolSpec
|
|
}
|
|
|
|
// Response is the final assembled assistant turn.
|
|
type Response struct {
|
|
Content string
|
|
ToolCalls []ToolCall
|
|
FinishReason string
|
|
}
|
|
|
|
// DeltaFunc receives streamed text tokens. May be nil.
|
|
type DeltaFunc func(text string)
|
|
|
|
type Provider interface {
|
|
Chat(ctx context.Context, req Request, onDelta DeltaFunc) (Response, error)
|
|
}
|