ai

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package ai provides LLM integration for AI-assisted workflow generation.

Index

Constants

View Source
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

func DefaultModels() map[string]string

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

func StripFences(s string) string

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

func StripHCLContext(dir string) (string, bool)

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

func SystemPrompt(providerName string) string

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

func NewAnthropic(apiKey string) (*Anthropic, error)

NewAnthropic creates an Anthropic provider, reading the API key from the environment or the provided key string.

func (*Anthropic) Generate

Generate calls the Anthropic Messages API.

func (*Anthropic) Name

func (a *Anthropic) Name() string

Name returns the provider name.

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, []string)

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

func (c Config) ResolveAPIKey(providerName string) string

ResolveAPIKey returns the API key for the given provider, applying the resolution order: env var > config file.

func (Config) ResolveModel

func (c Config) ResolveModel(providerName, cliFlag string) string

ResolveModel returns the model for the given provider, applying the resolution order: CLI flag > config file > provider default.

func (Config) ResolveProviderName

func (c Config) ResolveProviderName(cliFlag string) string

ResolveProviderName returns the provider name to use, applying the resolution order: CLI flag > config default > "anthropic".

type GenerateRequest

type GenerateRequest struct {
	SystemPrompt string
	UserPrompt   string
	Model        string
}

GenerateRequest holds the parameters for an LLM generation call.

type GenerateResponse

type GenerateResponse struct {
	Text         string
	InputTokens  int64
	OutputTokens int64
}

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

func NewOpenAI(apiKey string) (*OpenAI, error)

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.

func (*OpenAI) Name

func (o *OpenAI) Name() string

Name returns the provider name.

type Provider

type Provider interface {
	Generate(ctx context.Context, req GenerateRequest) (GenerateResponse, error)
	Name() string
}

Provider defines the interface for LLM providers.

type ProviderConfig

type ProviderConfig struct {
	Model  string `yaml:"model"`
	APIKey string `yaml:"api_key"`
}

ProviderConfig holds per-provider settings from the config file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL