LocalAI/pkg/templates/multimodal.go
Ettore Di Giacinto 648ffdf449
feat(multimodal): allow to template placeholders (#3728)
feat(multimodal): allow to template image placeholders

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2024-10-04 18:32:29 +02:00

25 lines
466 B
Go

package templates
import (
"bytes"
"text/template"
)
func TemplateMultiModal(templateString string, templateID int, text string) (string, error) {
// compile the template
tmpl, err := template.New("template").Parse(templateString)
if err != nil {
return "", err
}
result := bytes.NewBuffer(nil)
// execute the template
err = tmpl.Execute(result, struct {
ID int
Text string
}{
ID: templateID,
Text: text,
})
return result.String(), err
}