Capture keyed prompts and source-backed content at load time
This commit is contained in:
@@ -76,7 +76,7 @@ func (r *goRenderer) Render(ctx context.Context, definition *domain.PromptDefini
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tmpl, parseErr := template.New(fmt.Sprintf("msg_%d", i)).Funcs(funcs).Option("missingkey=error").Parse(tmplMsg.Content)
|
||||
tmpl, parseErr := parseTemplate(fmt.Sprintf("msg_%d", i), tmplMsg.Content, funcs)
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func renderSessionID(ctx context.Context, raw string, funcs template.FuncMap, va
|
||||
if err := ctx.Err(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
tmpl, parseErr := template.New("session_id").Funcs(funcs).Option("missingkey=error").Parse(raw)
|
||||
tmpl, parseErr := parseTemplate("session_id", raw, funcs)
|
||||
if err := ctx.Err(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
15
internal/prompt/template.go
Normal file
15
internal/prompt/template.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package prompt
|
||||
|
||||
import "text/template"
|
||||
|
||||
// CompileTemplate checks static syntax with the same grammar and function
|
||||
// names as rendering, without evaluating request inputs or variables.
|
||||
func CompileTemplate(name, raw string) (*template.Template, error) {
|
||||
return parseTemplate(name, raw, template.FuncMap{
|
||||
"input": func(string) (string, error) { return "", nil },
|
||||
})
|
||||
}
|
||||
|
||||
func parseTemplate(name, raw string, funcs template.FuncMap) (*template.Template, error) {
|
||||
return template.New(name).Funcs(funcs).Option("missingkey=error").Parse(raw)
|
||||
}
|
||||
Reference in New Issue
Block a user