Documentation
¶
Overview ¶
Package ai provides LLM integration for AI-assisted workflow generation.
Index ¶
Constants ¶
const ( // DefaultTimeout is the maximum time to wait for an LLM response. DefaultTimeout = 120 * time.Second // DefaultMaxTokens is the maximum number of tokens in the LLM response. DefaultMaxTokens = 4096 )
Variables ¶
This section is empty.
Functions ¶
func StripFences ¶
StripFences removes markdown code fences from LLM output, returning clean YAML.
func StripHCLContext ¶
StripHCLContext reads HCL files from the given directory, strips all string literal values, heredoc content, and comments, then returns the structural skeleton. Returns an empty string if the directory doesn't exist or has no HCL files.
func SystemPrompt ¶
SystemPrompt returns the system prompt for the given CI provider name.
Types ¶
type Anthropic ¶
type Anthropic struct {
// contains filtered or unexported fields
}
Anthropic implements the Provider interface using the Anthropic API.
func NewAnthropic ¶
NewAnthropic creates an Anthropic provider, reading the API key from the environment or the provided key string.
func (*Anthropic) Generate ¶
func (a *Anthropic) Generate(ctx context.Context, req GenerateRequest) (GenerateResponse, error)
Generate calls the Anthropic Messages API.
type Config ¶
type Config struct {
Default string `yaml:"default"`
Providers map[string]ProviderConfig `yaml:"providers"`
}
Config represents the AI section of the cinzel config file.
func LoadConfig ¶
func LoadConfig() Config
LoadConfig reads the cinzel config file from os.UserConfigDir()/cinzel/config.yaml. Returns an empty Config (not an error) if the file doesn't exist.
func (Config) ResolveAPIKey ¶
ResolveAPIKey returns the API key for the given provider, applying the resolution order: env var > config file.
func (Config) ResolveModel ¶
ResolveModel returns the model for the given provider, applying the resolution order: CLI flag > config file > provider default.
func (Config) ResolveProviderName ¶
ResolveProviderName returns the provider name to use, applying the resolution order: CLI flag > config default > "anthropic".
type GenerateRequest ¶
GenerateRequest holds the parameters for an LLM generation call.
type GenerateResponse ¶
GenerateResponse holds the LLM response text and token usage.
func GenerateWithTimeout ¶
func GenerateWithTimeout(ctx context.Context, p Provider, req GenerateRequest) (GenerateResponse, error)
GenerateWithTimeout calls the provider with a timeout and validates the response.
func (GenerateResponse) TotalTokens ¶
func (r GenerateResponse) TotalTokens() int64
TotalTokens returns the sum of input and output tokens.
type OpenAI ¶
type OpenAI struct {
// contains filtered or unexported fields
}
OpenAI implements the Provider interface using the OpenAI API.
func NewOpenAI ¶
NewOpenAI creates an OpenAI provider, reading the API key from the environment or the provided key string.
func (*OpenAI) Generate ¶
func (o *OpenAI) Generate(ctx context.Context, req GenerateRequest) (GenerateResponse, error)
Generate calls the OpenAI Chat Completions API.
type Provider ¶
type Provider interface {
Generate(ctx context.Context, req GenerateRequest) (GenerateResponse, error)
Name() string
}
Provider defines the interface for LLM providers.
type ProviderConfig ¶
ProviderConfig holds per-provider settings from the config file.