embedregistry

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package embedregistry provides an embed.FS-based prompt registry that loads all YAML manifests at construction (eager). Use New with an fs.FS and root path; GetTemplate performs an O(1) lookup by id. Template name must not contain ':' (used as cache key separator).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Registry)

Option configures a Registry.

func WithPartials added in v0.3.0

func WithPartials(pattern string) Option

WithPartials sets a pattern relative to root for partials (e.g. "partials/*.tmpl"); one shared partials dir for all manifests.

func WithVersion added in v0.3.0

func WithVersion(version string) Option

WithVersion sets a build or git version (e.g. from -ldflags). Stat returns it as TemplateInfo.Version.

type Registry

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

Registry loads all YAML manifests from an fs.FS at construction (eager). No mutex. Holds parsed templates by id.

func New

func New(fsys fs.FS, root string, opts ...Option) (*Registry, error)

New walks fsys, parses every .yaml/.yml file under the given root, and returns a Registry. id = basename without extension (e.g. "agent", "agent.prod").

Example
reg, err := New(exampleFS, "testdata/prompts")
if err != nil {
	panic(err)
}
ctx := context.Background()
tpl, err := reg.GetTemplate(ctx, "agent")
if err != nil {
	panic(err)
}
fmt.Println(tpl.Metadata.ID)
fmt.Println(len(tpl.Messages))
Output:

agent
1

func (*Registry) GetTemplate

func (r *Registry) GetTemplate(ctx context.Context, id string) (*prompty.ChatPromptTemplate, error)

GetTemplate returns a template by id. O(1) map lookup. Enriches tpl.Metadata.Version from Stat if empty.

Example
reg, err := New(exampleFS, "testdata/prompts")
if err != nil {
	panic(err)
}
ctx := context.Background()
tpl, err := reg.GetTemplate(ctx, "agent")
if err != nil {
	panic(err)
}
type Payload struct {
	UserName string `prompt:"user_name"`
}
exec, err := tpl.FormatStruct(ctx, &Payload{UserName: "Bob"})
if err != nil {
	panic(err)
}
text := exec.Messages[0].Content[0].(prompty.TextPart).Text
fmt.Println(text)
Output:

Agent Bob

func (*Registry) List added in v0.3.0

func (r *Registry) List(ctx context.Context) ([]string, error)

List returns all template ids (order from walk).

func (*Registry) Stat added in v0.3.0

Stat returns metadata for id without parsing. Version from WithVersion; UpdatedAt is zero for embed.

Jump to

Keyboard shortcuts

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