Files
ctxGPT/promptBuilder/promptBuilder.go
2024-03-08 01:13:27 -07:00

22 lines
462 B
Go

package promptBuilder
import (
"bytes"
"fmt"
"text/template"
)
func BuildPrompt(name string, in interface{}) (string, error) {
fileLocation := "./prompts/" + name
tmpl, err := template.New(name).ParseFiles(fileLocation)
if err != nil {
return "", fmt.Errorf("error parsing template: %w", err)
}
b := bytes.Buffer{}
err = tmpl.Execute(&b, in)
if err != nil {
return "", fmt.Errorf("error executing template: %w", err)
}
return b.String(), nil
}