Skip to content

Commit

Permalink
feat(templates): extract text from multimodal requests (#3866)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mudler authored Oct 17, 2024
1 parent 9db0683 commit d5da8c3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/backend/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package backend

import (
"context"
"encoding/json"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -77,6 +78,16 @@ func ModelInference(ctx context.Context, s string, messages []schema.Message, im
switch ct := message.Content.(type) {
case string:
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:
return nil, fmt.Errorf("unsupported type for schema.Message.Content for inference: %T", ct)
}
Expand Down

0 comments on commit d5da8c3

Please sign in to comment.