mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-24 06:46:39 +00:00
feat(templates): extract text from multimodal requests (#3866)
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>
This commit is contained in:
parent
9db068388b
commit
d5da8c3509
@ -2,6 +2,7 @@ package backend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -77,6 +78,16 @@ func ModelInference(ctx context.Context, s string, messages []schema.Message, im
|
|||||||
switch ct := message.Content.(type) {
|
switch ct := message.Content.(type) {
|
||||||
case string:
|
case string:
|
||||||
protoMessages[i].Content = ct
|
protoMessages[i].Content = ct
|
||||||
|
case []interface{}:
|
||||||
|
// If using the tokenizer template, in case of multimodal we want to keep the multimodal content as and return only strings here
|
||||||
|
data, _ := json.Marshal(ct)
|
||||||
|
resultData := []struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
}{}
|
||||||
|
json.Unmarshal(data, &resultData)
|
||||||
|
for _, r := range resultData {
|
||||||
|
protoMessages[i].Content += r.Text
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported type for schema.Message.Content for inference: %T", ct)
|
return nil, fmt.Errorf("unsupported type for schema.Message.Content for inference: %T", ct)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user