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 DefaultModels ¶ added in v0.6.0
DefaultModels returns the model each provider uses when the config names none, keyed by provider name. cinzel init writes the template from this, so a new config starts on whatever the code already defaults to.
func StripFences ¶
StripFences removes markdown code fences from LLM output, returning clean YAML.
An opening fence with no closer runs to the end of the text. A response cut off at the token limit ends that way, and it used to be returned verbatim, so the YAML parser was handed the "```yaml" line along with the document.
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.
The skeleton is not anonymous: file names, block types, block labels and attribute names are kept as written, since the structure is what makes the context worth sending at all. Only values are removed. Callers sending this to a third party have to say so.
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 ¶
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, and a warning for each thing worth saying about the file it did read.
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.