-
Notifications
You must be signed in to change notification settings - Fork 356
coordinator: extend audio/video media support alongside images #2659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
8445492
e18e8b3
3cdfcd7
91ed68b
6632ed4
d20fc39
9d5c53f
50e2d42
0602657
45f999f
69767ef
906bc39
1dc613b
9ce58c7
4daff52
beeeaa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,13 +134,32 @@ func (s *DecodeStep) injectTokensField(reqCtx *pipeline.RequestContext) { | |
| reqCtx.Body["tokens"] = tokens | ||
| } | ||
|
|
||
| // injectUUIDs tags each media content part with the uuid the decode | ||
| // backend uses for prefix-cache keying. Each part is paired with the | ||
| // MultimodalEntry that shares its modality and local index — the same | ||
| // invariant the encode fanout uses (see localIndexOf in utils.go). | ||
| // Non-media parts (text, tool_use, unknown types) are skipped. | ||
| func (s *DecodeStep) injectUUIDs(reqCtx *pipeline.RequestContext) { | ||
| messages, ok := reqCtx.Body["messages"].([]any) | ||
| if !ok { | ||
| return | ||
| } | ||
|
|
||
| hashIdx := 0 | ||
| // Build a (modality, localIndex) → Hash lookup once so per-part | ||
| // tagging stays O(1) even on requests with many media items. | ||
| hashByModLocalIdx := make(map[string]map[int]string) | ||
| for i, entry := range reqCtx.MultimodalEntries { | ||
| mod := entryModality(entry) | ||
| localIdx := localIndexOf(reqCtx.MultimodalEntries, i) | ||
| if _, ok := hashByModLocalIdx[mod]; !ok { | ||
| hashByModLocalIdx[mod] = make(map[int]string) | ||
| } | ||
| hashByModLocalIdx[mod][localIdx] = entry.Hash | ||
| } | ||
|
|
||
| // Walk parts, incrementing a per-modality counter so each media part | ||
| // gets the hash of the entry at the matching (modality, localIndex). | ||
| modCounter := make(map[string]int) | ||
| for _, msg := range messages { | ||
| msgMap, ok := msg.(map[string]any) | ||
| if !ok { | ||
|
|
@@ -155,12 +174,15 @@ func (s *DecodeStep) injectUUIDs(reqCtx *pipeline.RequestContext) { | |
| if !ok { | ||
| continue | ||
| } | ||
| if partMap["type"] != "image_url" { | ||
| partType, _ := partMap["type"].(string) | ||
| modality, isMedia := partTypeModality[partType] | ||
| if !isMedia { | ||
| continue | ||
| } | ||
| if hashIdx < len(reqCtx.MultimodalEntries) { | ||
| partMap["uuid"] = reqCtx.MultimodalEntries[hashIdx].Hash | ||
| hashIdx++ | ||
| localIdx := modCounter[modality] | ||
| modCounter[modality]++ | ||
| if h, ok := hashByModLocalIdx[modality][localIdx]; ok { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| partMap["uuid"] = h | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.