Documentation
¶
Overview ¶
Package buffs provides the buff interface for prompt transformations.
Buffs transform attempts by modifying prompts. They can add prefixes, encode text, translate languages, or apply other mutations to test LLM robustness against prompt variations.
Index ¶
- Variables
- func DefaultBuff(ctx context.Context, attempts []*attempt.Attempt, t Transformer) ([]*attempt.Attempt, error)
- func Get(name string) (func(registry.Config) (Buff, error), bool)
- func List() []string
- func NewBuffedProber(inner types.Prober, chain *BuffChain) types.Prober
- func Register(name string, factory func(registry.Config) (Buff, error))
- type Buff
- type BuffChain
- func (c *BuffChain) Apply(ctx context.Context, attempts []*attempt.Attempt) ([]*attempt.Attempt, error)
- func (c *BuffChain) ApplyPostBuffs(ctx context.Context, a *attempt.Attempt) (*attempt.Attempt, error)
- func (c *BuffChain) Buffs() []Buff
- func (c *BuffChain) HasPostBuffHooks() bool
- func (c *BuffChain) IsEmpty() bool
- func (c *BuffChain) Len() int
- func (c *BuffChain) Transform(a *attempt.Attempt) iter.Seq[*attempt.Attempt]
- type BuffedProber
- func (bp *BuffedProber) Description() string
- func (bp *BuffedProber) GetPrimaryDetector() string
- func (bp *BuffedProber) GetPrompts() []string
- func (bp *BuffedProber) Goal() string
- func (bp *BuffedProber) Name() string
- func (bp *BuffedProber) Probe(ctx context.Context, gen types.Generator) ([]*attempt.Attempt, error)
- type PostBuff
- type Transformer
Constants ¶
This section is empty.
Variables ¶
var Registry = registry.New[Buff]("buffs")
Registry is the global buff registry.
Functions ¶
func DefaultBuff ¶
func DefaultBuff(ctx context.Context, attempts []*attempt.Attempt, t Transformer) ([]*attempt.Attempt, error)
DefaultBuff provides the standard Buff() loop: iterate over input attempts, check for context cancellation between each, collect all Transform() results.
Most buff implementations have identical Buff() methods that follow this exact pattern. Using DefaultBuff eliminates that boilerplate.
Usage in a buff implementation:
func (b *MyBuff) Buff(ctx context.Context, attempts []*attempt.Attempt) ([]*attempt.Attempt, error) {
return buffs.DefaultBuff(ctx, attempts, b)
}
func NewBuffedProber ¶
NewBuffedProber wraps a prober with buff transformations. If the chain is nil or empty, it returns the inner prober directly (zero overhead). The generator is passed to Probe() at call time, not at construction.
Types ¶
type Buff ¶
type Buff interface {
// Buff transforms a slice of attempts, returning modified versions.
Buff(ctx context.Context, attempts []*attempt.Attempt) ([]*attempt.Attempt, error)
// Transform yields transformed attempts from a single input.
// Uses iter.Seq for lazy generation (Go 1.23+).
Transform(a *attempt.Attempt) iter.Seq[*attempt.Attempt]
// Name returns the buff's fully qualified name.
Name() string
// Description returns a human-readable description.
Description() string
}
Buff transforms attempts by modifying their prompts.
type BuffChain ¶
type BuffChain struct {
// contains filtered or unexported fields
}
BuffChain composes multiple buffs into a sequential pipeline.
func NewBuffChain ¶
NewBuffChain creates a chain from the given buffs.
func (*BuffChain) Apply ¶
func (c *BuffChain) Apply(ctx context.Context, attempts []*attempt.Attempt) ([]*attempt.Attempt, error)
Apply runs all buffs in sequence on the given attempts.
func (*BuffChain) ApplyPostBuffs ¶
func (c *BuffChain) ApplyPostBuffs(ctx context.Context, a *attempt.Attempt) (*attempt.Attempt, error)
ApplyPostBuffs runs any PostBuff.Untransform hooks on the attempt.
func (*BuffChain) HasPostBuffHooks ¶
HasPostBuffHooks returns true if any buff implements PostBuff.
type BuffedProber ¶
type BuffedProber struct {
// contains filtered or unexported fields
}
BuffedProber wraps a Prober and applies buff transformations.
func (*BuffedProber) Description ¶
func (bp *BuffedProber) Description() string
Description returns the probe description (delegated to inner if available).
func (*BuffedProber) GetPrimaryDetector ¶
func (bp *BuffedProber) GetPrimaryDetector() string
GetPrimaryDetector returns the primary detector (delegated to inner if available).
func (*BuffedProber) GetPrompts ¶
func (bp *BuffedProber) GetPrompts() []string
GetPrompts returns the probe prompts (delegated to inner if available).
func (*BuffedProber) Goal ¶
func (bp *BuffedProber) Goal() string
Goal returns the probe goal (delegated to inner if available).
func (*BuffedProber) Name ¶
func (bp *BuffedProber) Name() string
Name returns the probe name (delegated to inner).
type PostBuff ¶
type PostBuff interface {
Buff
// HasPostBuffHook returns true if this buff needs post-generation processing.
HasPostBuffHook() bool
// Untransform post-processes an attempt after generation.
Untransform(ctx context.Context, a *attempt.Attempt) (*attempt.Attempt, error)
}
PostBuff is an optional interface for buffs that need to post-process generator outputs after generation but before detection.