Documentation
¶
Overview ¶
Package llm defines the LLM provider interface and the canonical structured output type used for commitment classification.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnthropicProvider ¶
type AnthropicProvider struct {
// contains filtered or unexported fields
}
AnthropicProvider calls the Anthropic API using tool use to enforce structured JSON output matching ClassificationResult.
func NewAnthropic ¶
func NewAnthropic(apiKey, model string, maxRetries int) *AnthropicProvider
NewAnthropic creates an AnthropicProvider with the given API key and model. Use model "" to fall back to claude-opus-4-6.
func (*AnthropicProvider) Classify ¶
func (p *AnthropicProvider) Classify(ctx context.Context, systemPrompt, content string) (ClassificationResult, error)
Classify calls the Anthropic API, forcing a tool use response that matches ClassificationResult. Retries up to maxRetries times with exponential backoff.
type ClassificationResult ¶
type ClassificationResult struct {
IsCommitment bool `json:"is_commitment"`
Type string `json:"type"` // "hard", "soft", "dependency", "deadline_change", "none"
Confidence float64 `json:"confidence"` // 0.0-1.0
Statement string `json:"statement"` // Normalized commitment text
Owner string `json:"owner"` // Inferred owner (may be empty)
Deadline string `json:"deadline"` // ISO date string or empty
Reasoning string `json:"reasoning"` // Why classified as commitment
RejectionReason string `json:"rejection_reason"` // Why rejected (if !IsCommitment)
}
ClassificationResult is the structured output returned by any LLM provider when classifying a signal. All providers must return this exact shape.
type MockProvider ¶
type MockProvider struct {
// Responses maps content substrings to pre-configured results.
// The first matching key wins (iteration order is map-random, so use
// unique substrings to avoid ambiguity in tests).
Responses map[string]ClassificationResult
// Fallback is returned when no Responses key matches.
Fallback ClassificationResult
// CallCount tracks how many Classify calls have been made (for assertions).
CallCount int
}
MockProvider is a deterministic test double for Provider. Configure responses keyed by content substrings; unmatched content falls through to the Fallback value.
func NewMock ¶
func NewMock() *MockProvider
NewMock returns a MockProvider with an empty response map and a safe fallback (non-commitment, high confidence).
func (*MockProvider) Classify ¶
func (m *MockProvider) Classify(_ context.Context, _, content string) (ClassificationResult, error)
Classify returns the first matching pre-configured result, or the Fallback.
func (*MockProvider) WithResponse ¶
func (m *MockProvider) WithResponse(substring string, result ClassificationResult) *MockProvider
WithResponse registers a result for any content containing the given substring. Calls can be chained for test setup.
type OpenAIProvider ¶
type OpenAIProvider struct {
// contains filtered or unexported fields
}
OpenAIProvider calls the OpenAI API using function calling to enforce structured JSON output matching ClassificationResult.
func NewOpenAI ¶
func NewOpenAI(apiKey, model string, maxRetries int) *OpenAIProvider
NewOpenAI creates an OpenAIProvider with the given API key and model. Use model "" to fall back to gpt-4o.
func (*OpenAIProvider) Classify ¶
func (p *OpenAIProvider) Classify(ctx context.Context, systemPrompt, content string) (ClassificationResult, error)
Classify calls the OpenAI API with function calling to return a structured ClassificationResult. Retries up to maxRetries times with exponential backoff.
type Provider ¶
type Provider interface {
// Classify sends the system prompt + user content to the LLM and returns
// a structured ClassificationResult.
Classify(ctx context.Context, systemPrompt, content string) (ClassificationResult, error)
}
Provider abstracts the LLM backend. Swap providers without changing pipeline code.