make the chat work

This commit is contained in:
2024-03-08 01:13:27 -07:00
parent 1ed6023a14
commit 917c00c23a
5 changed files with 398 additions and 90 deletions

View File

@ -0,0 +1,21 @@
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
}