make the chat work
This commit is contained in:
21
promptBuilder/promptBuilder.go
Normal file
21
promptBuilder/promptBuilder.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user