"docs/source/en/using-diffusers/img2img.mdx" did not exist on "44968e42047140e6a8192b5e65a9b03e5053ddc3"
Unverified Commit 1f05d771 authored by Michael Yang's avatar Michael Yang Committed by GitHub
Browse files

Merge pull request #1244 from jmorganca/brucemacd/no-fail-template

do not fail on unsupported template variables
parents c3ff3608 47d4e226
......@@ -58,18 +58,21 @@ type PromptVars struct {
func (m *Model) Prompt(p PromptVars) (string, error) {
var prompt strings.Builder
tmpl, err := template.New("").Parse(m.Template)
// Use the "missingkey=zero" option to handle missing variables without panicking
tmpl, err := template.New("").Option("missingkey=zero").Parse(m.Template)
if err != nil {
return "", err
}
if p.System == "" {
// use the default system prompt for this model if one is not specified
p.System = m.System
vars := map[string]any{
"System": p.System,
"Prompt": p.Prompt,
"Response": p.Response,
"First": p.First,
}
var sb strings.Builder
if err := tmpl.Execute(&sb, p); err != nil {
if err := tmpl.Execute(&sb, vars); err != nil {
return "", err
}
prompt.WriteString(sb.String())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment