Add embedded prompt registry
This commit is contained in:
28
internal/framework/prompt/render.go
Normal file
28
internal/framework/prompt/render.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user