@@ -12,6 +12,7 @@ import (
12
12
"github.com/mudler/LocalAI/core/schema"
13
13
"github.com/mudler/LocalAI/pkg/functions"
14
14
"github.com/mudler/LocalAI/pkg/model"
15
+ "github.com/mudler/LocalAI/pkg/templates"
15
16
"github.com/mudler/LocalAI/pkg/utils"
16
17
"github.com/rs/zerolog/log"
17
18
)
@@ -168,8 +169,13 @@ func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIReque
168
169
continue CONTENT
169
170
}
170
171
input .Messages [i ].StringVideos = append (input .Messages [i ].StringVideos , base64 ) // TODO: make sure that we only return base64 stuff
172
+
173
+ t := "[vid-{{.ID}}]{{.Text}}"
174
+ if config .TemplateConfig .Video != "" {
175
+ t = config .TemplateConfig .Video
176
+ }
171
177
// set a placeholder for each image
172
- input .Messages [i ].StringContent = fmt . Sprintf ( "[vid-%d]" , vidIndex ) + input .Messages [i ].StringContent
178
+ input .Messages [i ].StringContent , _ = templates . TemplateMultiModal ( t , vidIndex , input .Messages [i ].StringContent )
173
179
vidIndex ++
174
180
case "audio_url" , "audio" :
175
181
// Decode content as base64 either if it's an URL or base64 text
@@ -180,7 +186,11 @@ func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIReque
180
186
}
181
187
input .Messages [i ].StringAudios = append (input .Messages [i ].StringAudios , base64 ) // TODO: make sure that we only return base64 stuff
182
188
// set a placeholder for each image
183
- input .Messages [i ].StringContent = fmt .Sprintf ("[audio-%d]" , audioIndex ) + input .Messages [i ].StringContent
189
+ t := "[audio-{{.ID}}]{{.Text}}"
190
+ if config .TemplateConfig .Audio != "" {
191
+ t = config .TemplateConfig .Audio
192
+ }
193
+ input .Messages [i ].StringContent , _ = templates .TemplateMultiModal (t , audioIndex , input .Messages [i ].StringContent )
184
194
audioIndex ++
185
195
case "image_url" , "image" :
186
196
// Decode content as base64 either if it's an URL or base64 text
@@ -189,9 +199,14 @@ func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIReque
189
199
log .Error ().Msgf ("Failed encoding image: %s" , err )
190
200
continue CONTENT
191
201
}
202
+
203
+ t := "[img-{{.ID}}]{{.Text}}"
204
+ if config .TemplateConfig .Image != "" {
205
+ t = config .TemplateConfig .Image
206
+ }
192
207
input .Messages [i ].StringImages = append (input .Messages [i ].StringImages , base64 ) // TODO: make sure that we only return base64 stuff
193
208
// set a placeholder for each image
194
- input .Messages [i ].StringContent = fmt . Sprintf ( "[img-%d]" , imgIndex ) + input .Messages [i ].StringContent
209
+ input .Messages [i ].StringContent , _ = templates . TemplateMultiModal ( t , imgIndex , input .Messages [i ].StringContent )
195
210
imgIndex ++
196
211
}
197
212
}
0 commit comments