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
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
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 ¶
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 ¶
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