Documentation
¶
Index ¶
- func CoerceJSONVariableStrings(vars map[string]any) map[string]any
- func ExamplesFilePath(tmplPath string) string
- func ParseStructuredPayload(rendered string, fallbackState map[string]interface{}) (string, string, error)
- func SampleVarsFromExamples(ef *ExamplesFile) map[string]string
- func ValidateRenderedPayload(rendered string, fallbackVars map[string]any, allowWideChoices bool, ...) error
- type Engine
- type ExampleSpec
- type ExamplesFile
- type StructuredPayload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoerceJSONVariableStrings ¶ added in v0.4.3
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
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 ¶
RenderFile loads a template file from disk and executes it with the given data.
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.