mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-28 14:35:00 +00:00
feat(multimodal): allow to template placeholders (#3728)
feat(multimodal): allow to template image placeholders Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
04c0841ca9
commit
648ffdf449
5 changed files with 66 additions and 4 deletions
|
@ -314,7 +314,7 @@ func (ml *ModelLoader) grpcModel(backend string, o *Options) func(string, string
|
|||
|
||||
client = NewModel(modelID, serverAddress, process)
|
||||
} else {
|
||||
log.Debug().Msg("external backend is uri")
|
||||
log.Debug().Msg("external backend is a uri")
|
||||
// address
|
||||
client = NewModel(modelID, uri, nil)
|
||||
}
|
||||
|
|
24
pkg/templates/multimodal.go
Normal file
24
pkg/templates/multimodal.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
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
|
||||
}
|
19
pkg/templates/multimodal_test.go
Normal file
19
pkg/templates/multimodal_test.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package templates_test
|
||||
|
||||
import (
|
||||
. "github.com/mudler/LocalAI/pkg/templates" // Update with your module path
|
||||
|
||||
// Update with your module path
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("EvaluateTemplate", func() {
|
||||
Context("templating simple strings for multimodal chat", func() {
|
||||
It("should template messages correctly", func() {
|
||||
result, err := TemplateMultiModal("[img-{{.ID}}]{{.Text}}", 1, "bar")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(result).To(Equal("[img-1]bar"))
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue