template

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoerceJSONVariableStrings added in v0.4.3

func CoerceJSONVariableStrings(vars map[string]any) map[string]any

CoerceJSONVariableStrings converts string values in vars that encode JSON arrays ("[...]") into parsed slices so templates iterating with {{ range .options }} work when fed stringified SampleVars.

func ExamplesFilePath added in v0.4.3

func ExamplesFilePath(tmplPath string) string

ExamplesFilePath returns the companion .examples.json path for a .json.tmpl file path.

func ParseStructuredPayload

func ParseStructuredPayload(rendered string, fallbackState map[string]interface{}) (string, string, error)

ParseStructuredPayload parses rendered output that has separate "schema" and "state" envelopes, or treats the full payload as the schema if not wrapped, and normalizes legacy question fields ("name" -> "id", "question"/"prompt" -> "instructions", "items" -> "levels", dict "options" -> list) so that all templates and ad-hoc schemas conform to structured_server.py's parse_schema contract.

func SampleVarsFromExamples added in v0.4.3

func SampleVarsFromExamples(ef *ExamplesFile) map[string]string

SampleVarsFromExamples converts the "typical" example (or first example) in ef into string-valued sample variables suitable for GET /api/templates and Studio form inputs.

func ValidateRenderedPayload added in v0.4.3

func ValidateRenderedPayload(rendered string, fallbackVars map[string]any, allowWideChoices bool, expectedAnswers map[string]string) error

ValidateRenderedPayload parses rendered through ParseStructuredPayload and checks that the resulting schema and state satisfy structured_server.py's parse_schema contract, option limits, DAG rules, and any expectedAnswers keys/values.

Types

type Engine

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

Engine parses and executes Go templates with rich helper functions.

func NewEngine

func NewEngine() *Engine

NewEngine creates a new template engine with default helper functions.

func (*Engine) RenderFile

func (e *Engine) RenderFile(filePath string, data map[string]interface{}) (string, error)

RenderFile loads a template file from disk and executes it with the given data.

func (*Engine) RenderString

func (e *Engine) RenderString(name, tmplStr string, data map[string]interface{}) (string, error)

RenderString parses and executes an in-memory template string.

type ExampleSpec added in v0.4.3

type ExampleSpec struct {
	Name            string            `json:"name"`
	Unambiguous     bool              `json:"unambiguous,omitempty"`
	Variables       map[string]any    `json:"variables"`
	ExpectedAnswers map[string]string `json:"expected_answers,omitempty"`
}

ExampleSpec defines a single synthetic input case (for example "typical", "edge", or "minimal") for a policy template (.json.tmpl) along with optional unambiguous expected slot answers.

type ExamplesFile added in v0.4.3

type ExamplesFile struct {
	Multimodal       *bool         `json:"multimodal,omitempty"`
	AllowWideChoices bool          `json:"allow_wide_choices,omitempty"`
	Examples         []ExampleSpec `json:"examples"`
}

ExamplesFile holds the sidecar <template>.examples.json metadata and test inputs for a .json.tmpl file.

func LoadExamplesFile added in v0.4.3

func LoadExamplesFile(path string) (*ExamplesFile, error)

LoadExamplesFile reads and decodes a <template>.examples.json file.

type StructuredPayload

type StructuredPayload struct {
	Schema json.RawMessage `json:"schema"`
	State  json.RawMessage `json:"state"`
}

StructuredPayload represents the rendered JSON package containing a schema and state.

Jump to

Keyboard shortcuts

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