-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(multimodal): allow to template placeholders (#3728)
feat(multimodal): allow to template image placeholders Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
- Loading branch information
Showing
5 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) | ||
}) | ||
}) | ||
}) |