match

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Project

func Project(results []Result) []any

Project returns a JSON-compatible, defensively owned representation of ordered Match results.

Types

type Arg

type Arg struct {
	Value    any
	Var      Var
	HasValue bool
}

Arg holds a matched argument's value along with its definition.

type Example

type Example struct {
	Subject     string `json:"-"`
	UserText    string `json:"-"`
	FormattedTo string `json:"-"`
}

Example is a structured grounding example for the prompt.

func (Example) MarshalJSON

func (e Example) MarshalJSON() ([]byte, error)

func (*Example) UnmarshalJSON

func (e *Example) UnmarshalJSON(b []byte) error

func (*Example) UnmarshalYAML

func (e *Example) UnmarshalYAML(b []byte) error

UnmarshalYAML implements yaml.Unmarshaler for Example.

type MatchOption

type MatchOption func(*matchConfig)

func WithGenerator

func WithGenerator(gen genx.Generator) MatchOption

WithGenerator sets a custom generator for Match.

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

Matcher is a compiled matcher built from rules.

func Compile

func Compile(rules []*Rule, opts ...Option) (*Matcher, error)

Compile compiles rules into a reusable Matcher.

func (*Matcher) Match

func (m *Matcher) Match(ctx context.Context, pattern string, mc genx.ModelContext, opts ...MatchOption) iter.Seq2[Result, error]

Match executes the matcher against user input and returns streaming results.

func (*Matcher) Parse

func (m *Matcher) Parse(chunks iter.Seq2[string, error]) iter.Seq2[Result, error]

Parse converts arbitrary text chunks into ordered Match results. Chunk boundaries do not affect line framing.

func (*Matcher) SystemPrompt

func (m *Matcher) SystemPrompt() string

SystemPrompt returns the rendered system prompt for debugging.

type Option

type Option func(*compileConfig)

func WithTpl

func WithTpl(tpl string) Option

WithTpl sets a custom prompt template.

type Pattern

type Pattern struct {
	Input  string `json:"-"`
	Output string `json:"-"`
}

Pattern is a single input/output pattern example for one rule.

func (Pattern) MarshalJSON

func (p Pattern) MarshalJSON() ([]byte, error)

func (*Pattern) UnmarshalJSON

func (p *Pattern) UnmarshalJSON(b []byte) error

func (*Pattern) UnmarshalYAML

func (p *Pattern) UnmarshalYAML(b []byte) error

UnmarshalYAML implements yaml.Unmarshaler for Pattern.

type Result

type Result struct {
	Rule    string
	Args    map[string]Arg
	RawText string
}

Result is the structured output from a single match.

func Collect

func Collect(seq iter.Seq2[Result, error]) ([]Result, error)

Collect consumes a streaming sequence into a slice.

type Rule

type Rule struct {
	Name       string            `json:"name" yaml:"name"`
	References map[string]string `json:"references,omitempty" yaml:"references,omitempty"`
	Vars       map[string]Var    `json:"vars,omitempty" yaml:"vars,omitempty"`
	Patterns   []Pattern         `json:"patterns,omitempty" yaml:"patterns,omitempty"`
	Examples   []Example         `json:"examples,omitempty" yaml:"examples,omitempty"`
}

Rule is a schema-driven rule definition.

func ParseRuleYAML

func ParseRuleYAML(data []byte) (*Rule, error)

ParseRuleYAML parses a Rule from YAML bytes.

type Var

type Var struct {
	Label string `json:"label" yaml:"label"`
	Type  string `json:"type" yaml:"type"`
}

Var defines a variable to be extracted from user input.

Jump to

Keyboard shortcuts

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