Skip to content

Commit 79b076a

Browse files
committed
feat(templates): extract text from multimodal requests
When offloading template construction to the backend, we want to keep text around in case of multimodal requests. Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 54c0f15 commit 79b076a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

core/backend/llm.go

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package backend
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"os"
78
"regexp"
@@ -77,6 +78,16 @@ func ModelInference(ctx context.Context, s string, messages []schema.Message, im
7778
switch ct := message.Content.(type) {
7879
case string:
7980
protoMessages[i].Content = ct
81+
case []interface{}:
82+
// If using the tokenizer template, in case of multimodal we want to keep the multimodal content as and return only strings here
83+
data, _ := json.Marshal(ct)
84+
resultData := []struct {
85+
Text string `json:"text"`
86+
}{}
87+
json.Unmarshal(data, &resultData)
88+
for _, r := range resultData {
89+
protoMessages[i].Content += r.Text
90+
}
8091
default:
8192
return nil, fmt.Errorf("unsupported type for schema.Message.Content for inference: %T", ct)
8293
}

0 commit comments

Comments
 (0)