Documentation
¶
Overview ¶
Package llm defines the pluggable LLM provider interface and message types.
Index ¶
Constants ¶
const ( RoleUser = "user" RoleAssistant = "assistant" BlockText = "text" BlockToolUse = "tool_use" BlockToolResult = "tool_result" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Anthropic ¶
type Anthropic struct {
// contains filtered or unexported fields
}
Anthropic implements Provider using the Anthropic Messages API.
func NewAnthropic ¶
func NewAnthropic(cfg config.ProviderConfig) (*Anthropic, error)
NewAnthropic creates an Anthropic provider from the given config.
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
Content string `json:"content,omitempty"`
IsError bool `json:"is_error,omitempty"`
}
ContentBlock is a union type discriminated by Type:
- "text": Text is set
- "tool_use": ID (call ID), Name, and Input are set
- "tool_result": ID (matching tool_use call ID), Content, and IsError are set
type LoggingProvider ¶
type LoggingProvider struct {
// contains filtered or unexported fields
}
LoggingProvider wraps a Provider and writes every request/response exchange as JSONL to a file for prompt diagnostics.
func NewLoggingProvider ¶
func NewLoggingProvider(inner Provider, dir string) (*LoggingProvider, error)
NewLoggingProvider creates a provider that logs all exchanges to a JSONL file in the given directory. The file is named with a timestamp.
func (*LoggingProvider) Path ¶
func (l *LoggingProvider) Path() string
Path returns the log file path.
type Message ¶
type Message struct {
Role string `json:"role"`
Content []ContentBlock `json:"content"`
}
Message is a single message in a conversation.
func NewTextMessage ¶
NewTextMessage creates a simple text message.
func NewToolResultMessage ¶
NewToolResultMessage creates a tool_result message.
type OpenAI ¶
type OpenAI struct {
// contains filtered or unexported fields
}
OpenAI implements Provider using the OpenAI Chat Completions API.
type Provider ¶
Provider is the interface for LLM backends that support tool use.
func NewProvider ¶
func NewProvider(cfg config.ProviderConfig) (Provider, error)
NewProvider creates a Provider from the given config. The returned provider is wrapped with retry logic for transient errors.
type Response ¶
type Response struct {
Content []ContentBlock
StopReason StopReason
Usage Usage
}
Response is the model's response to a completion request.
func (*Response) TextContent ¶
TextContent returns the concatenated text from all text blocks.
func (*Response) ToolUseBlocks ¶
func (r *Response) ToolUseBlocks() []ContentBlock
ToolUseBlocks returns only the tool_use content blocks from a response.
type RetryProvider ¶
type RetryProvider struct {
// contains filtered or unexported fields
}
RetryProvider wraps a Provider with exponential backoff retry for transient errors.
func NewRetryProvider ¶
func NewRetryProvider(inner Provider, maxRetries int, baseDelay time.Duration) *RetryProvider
NewRetryProvider wraps inner with retry logic. maxRetries is the number of retries after the first attempt (so total attempts = maxRetries + 1).
type StopReason ¶
type StopReason string
StopReason indicates why the model stopped generating.
const ( StopEndTurn StopReason = "end_turn" StopToolUse StopReason = "tool_use" StopMaxTokens StopReason = "max_tokens" )