Documentation
¶
Overview ¶
Package ai provides AI provider abstraction and lazy configuration. All AI operations go through this package, which handles provider selection, configuration prompting, and LLM calls.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigPath ¶
ConfigPath returns the path to the devlore config file.
func SaveConfig ¶
SaveConfig saves AI configuration to the config file.
Types ¶
type AnthropicProvider ¶
type AnthropicProvider struct {
// contains filtered or unexported fields
}
AnthropicProvider implements Provider for Anthropic Claude.
func NewAnthropicProvider ¶
func NewAnthropicProvider(apiKey, model string) *AnthropicProvider
NewAnthropicProvider creates an Anthropic provider.
func (*AnthropicProvider) Available ¶
func (a *AnthropicProvider) Available(ctx context.Context) bool
Available checks if the API key is valid.
func (*AnthropicProvider) Chat ¶
func (a *AnthropicProvider) Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)
Chat sends a chat completion request to Anthropic.
func (*AnthropicProvider) Name ¶
func (a *AnthropicProvider) Name() string
Name returns "anthropic".
type ChatRequest ¶
type ChatRequest struct {
SystemPrompt string // System prompt (instructions)
Messages []Message // Conversation messages
Temperature float64 // 0.0 for deterministic, higher for creativity
MaxTokens int // Maximum response tokens (0 = provider default)
JSONMode bool // Request JSON output if supported
}
ChatRequest represents a chat completion request.
type ChatResponse ¶
type ChatResponse struct {
Content string // Response text
FinishReason string // "stop", "length", etc.
TokensUsed int // Total tokens consumed
}
ChatResponse contains the AI response.
type Config ¶
type Config struct {
Provider string `yaml:"provider"` // ollama, anthropic, openai, azure-openai
Model string `yaml:"model"` // Model name (e.g., "llama3.1:8b", "claude-sonnet-4-20250514")
Endpoint string `yaml:"endpoint"` // API endpoint (optional, for custom/azure)
APIKey string `yaml:"api_key"` // API key (for cloud providers)
}
Config holds AI provider configuration per ADR-017.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default configuration (Ollama).
func LoadConfig ¶
LoadConfig loads AI configuration from the config file. Returns nil config (not error) if no config exists.
type OllamaProvider ¶
type OllamaProvider struct {
// contains filtered or unexported fields
}
OllamaProvider implements Provider for local Ollama.
func NewOllamaProvider ¶
func NewOllamaProvider(endpoint, model string) *OllamaProvider
NewOllamaProvider creates an Ollama provider.
func (*OllamaProvider) Available ¶
func (o *OllamaProvider) Available(ctx context.Context) bool
Available checks if Ollama is running and the model is available.
func (*OllamaProvider) Chat ¶
func (o *OllamaProvider) Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)
Chat sends a chat completion request to Ollama.
type OpenAIProvider ¶
type OpenAIProvider struct {
// contains filtered or unexported fields
}
OpenAIProvider implements Provider for OpenAI and compatible APIs.
func NewOpenAIProvider ¶
func NewOpenAIProvider(apiKey, model, endpoint string) *OpenAIProvider
NewOpenAIProvider creates an OpenAI provider. endpoint can be empty for api.openai.com, or set for Azure/compatible APIs.
func (*OpenAIProvider) Available ¶
func (o *OpenAIProvider) Available(ctx context.Context) bool
Available checks if the API key is set.
func (*OpenAIProvider) Chat ¶
func (o *OpenAIProvider) Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)
Chat sends a chat completion request to OpenAI.
type Provider ¶
type Provider interface {
// Chat sends messages and returns a response.
Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)
// Name returns the provider name (e.g., "ollama", "anthropic").
Name() string
// Available returns true if the provider is ready to use.
Available(ctx context.Context) bool
}
Provider is the interface for AI backends.
func EnsureProvider ¶
EnsureProvider returns a configured AI provider, prompting the user if needed. If noAI is true, returns nil without prompting.
func NewProvider ¶
NewProvider creates a provider from configuration.