mirror of
https://github.com/mudler/LocalAI.git
synced 2026-01-06 02:29:54 -06:00
* WIP
* wip
* wip
* Make it compile
* Update json.hpp
* this shouldn't be private for now
* Add logs
* Reset auto detected template
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Re-enable grammars
* This seems to be broken - 360a9c98e1 (diff-a18a8e64e12a01167d8e98fc)[…]cccf0d4eed09d76d879L2998-L3207
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Placeholder
* Simplify image loading
* use completion type
* disable streaming
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* correctly return timings
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Remove some debug logging
* Adapt tests
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Keep header
* embedding: do not use oai type
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Sync from server.cpp
* Use utils and json directly from llama.cpp
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Sync with upstream
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* fix: copy json.hpp from the correct location
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* fix: add httplib
* sync llama.cpp
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Embeddiongs: set OAICOMPAT_TYPE_EMBEDDING
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* feat: sync with server.cpp by including it
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* make it darwin-compatible
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
---------
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package templates
|
|
|
|
import (
|
|
"bytes"
|
|
"text/template"
|
|
|
|
"github.com/Masterminds/sprig/v3"
|
|
)
|
|
|
|
type MultiModalOptions struct {
|
|
TotalImages int
|
|
TotalAudios int
|
|
TotalVideos int
|
|
|
|
ImagesInMessage int
|
|
AudiosInMessage int
|
|
VideosInMessage int
|
|
}
|
|
|
|
type MultimodalContent struct {
|
|
ID int
|
|
}
|
|
|
|
// https://github.com/ggml-org/llama.cpp/blob/be1d4a13db26750fac702ceb3af88ae4f39dc9f4/tools/mtmd/mtmd.h#L42
|
|
const DefaultMultiModalTemplate = "{{ range .Audio }}[audio-{{.ID}}]{{end}}{{ range .Images }}<__image__>{{end}}{{ range .Video }}[vid-{{.ID}}]{{end}}{{.Text}}"
|
|
|
|
func TemplateMultiModal(templateString string, opts MultiModalOptions, text string) (string, error) {
|
|
if templateString == "" {
|
|
templateString = DefaultMultiModalTemplate
|
|
}
|
|
|
|
// compile the template
|
|
tmpl, err := template.New("template").Funcs(sprig.FuncMap()).Parse(templateString)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
videos := []MultimodalContent{}
|
|
for i := 0; i < opts.VideosInMessage; i++ {
|
|
videos = append(videos, MultimodalContent{ID: i + (opts.TotalVideos - opts.VideosInMessage)})
|
|
}
|
|
|
|
audios := []MultimodalContent{}
|
|
for i := 0; i < opts.AudiosInMessage; i++ {
|
|
audios = append(audios, MultimodalContent{ID: i + (opts.TotalAudios - opts.AudiosInMessage)})
|
|
}
|
|
|
|
images := []MultimodalContent{}
|
|
for i := 0; i < opts.ImagesInMessage; i++ {
|
|
images = append(images, MultimodalContent{ID: i + (opts.TotalImages - opts.ImagesInMessage)})
|
|
}
|
|
|
|
result := bytes.NewBuffer(nil)
|
|
// execute the template
|
|
err = tmpl.Execute(result, struct {
|
|
Audio []MultimodalContent
|
|
Images []MultimodalContent
|
|
Video []MultimodalContent
|
|
Text string
|
|
}{
|
|
Audio: audios,
|
|
Images: images,
|
|
Video: videos,
|
|
Text: text,
|
|
})
|
|
return result.String(), err
|
|
}
|