ai

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 16 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 StripFences

func StripFences(s string) string

StripFences removes markdown code fences from LLM output, returning clean YAML.

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.

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

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

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