Skip to content

Commit f11bf07

Browse files
jmorgancamxyng
authored andcommitted
use llm.ImageData
1 parent 8450bf6 commit f11bf07

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

llm/dyn_ext_server.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,10 @@ func newDynExtServer(library, model string, adapters, projectors []string, opts
161161
func (llm *dynExtServer) Predict(ctx context.Context, predict PredictOpts, fn func(PredictResult)) error {
162162
resp := newExtServerResp(128)
163163
defer freeExtServerResp(resp)
164-
var imageData []ImageData
164+
165165
if len(predict.Images) > 0 {
166-
for cnt, i := range predict.Images {
167-
imageData = append(imageData, ImageData{Data: i, ID: cnt})
168-
}
166+
slog.Info(fmt.Sprintf("loaded %d images", len(predict.Images)))
169167
}
170-
slog.Info(fmt.Sprintf("loaded %d images", len(imageData)))
171168

172169
request := map[string]any{
173170
"prompt": predict.Prompt,
@@ -189,7 +186,7 @@ func (llm *dynExtServer) Predict(ctx context.Context, predict PredictOpts, fn fu
189186
"penalize_nl": predict.Options.PenalizeNewline,
190187
"seed": predict.Options.Seed,
191188
"stop": predict.Options.Stop,
192-
"image_data": imageData,
189+
"image_data": predict.Images,
193190
"cache_prompt": true,
194191
}
195192

llm/llama.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const maxRetries = 3
6262
type PredictOpts struct {
6363
Prompt string
6464
Format string
65-
Images map[int]api.ImageData
65+
Images []ImageData
6666
Options api.Options
6767
}
6868

server/routes.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,12 @@ func GenerateHandler(c *gin.Context) {
312312
ch <- resp
313313
}
314314

315-
images := make(map[int]api.ImageData)
315+
var images []llm.ImageData
316316
for i := range req.Images {
317-
images[i] = req.Images[i]
317+
images = append(images, llm.ImageData{
318+
ID: i,
319+
Data: req.Images[i],
320+
})
318321
}
319322

320323
// Start prediction
@@ -1188,11 +1191,19 @@ func ChatHandler(c *gin.Context) {
11881191
ch <- resp
11891192
}
11901193

1194+
var imageData []llm.ImageData
1195+
for k, v := range images {
1196+
imageData = append(imageData, llm.ImageData{
1197+
ID: k,
1198+
Data: v,
1199+
})
1200+
}
1201+
11911202
// Start prediction
11921203
predictReq := llm.PredictOpts{
11931204
Prompt: prompt,
11941205
Format: req.Format,
1195-
Images: images,
1206+
Images: imageData,
11961207
Options: opts,
11971208
}
11981209
if err := loaded.runner.Predict(c.Request.Context(), predictReq, fn); err != nil {

0 commit comments

Comments
 (0)