Add embedded prompt registry

This commit is contained in:
2026-07-03 16:43:04 +00:00
parent 54b9851f65
commit 31b136f1e2
7 changed files with 371 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package prompt
import (
"bytes"
"fmt"
"strings"
)
// RenderUserSystem renders the system and user prompt pair for promptID.
func RenderUserSystem(promptID string, data any) (system string, user string, metadata Metadata, err error) {
trimmedID := strings.TrimSpace(promptID)
compiled, ok := promptRegistry[trimmedID]
if !ok {
return "", "", Metadata{}, fmt.Errorf("unknown prompt id %q", promptID)
}
var systemBuf bytes.Buffer
if err := compiled.systemTmpl.Execute(&systemBuf, data); err != nil {
return "", "", Metadata{}, fmt.Errorf("render system prompt %q: %w", trimmedID, err)
}
var userBuf bytes.Buffer
if err := compiled.userTmpl.Execute(&userBuf, data); err != nil {
return "", "", Metadata{}, fmt.Errorf("render user prompt %q: %w", trimmedID, err)
}
return strings.TrimSpace(systemBuf.String()), strings.TrimSpace(userBuf.String()), compiled.metadata, nil
}