feat: native image/audio/video content parts (LocalAI)#63
Merged
Conversation
…rapper (+ marshal robustness)
98378b1 to
fc355f9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds native image / audio / video content parts to cogito, serialized by the LocalAI client, so agents can hand a model a voice note, image, or clip — not just text. go-openai's
ChatMessagePartmodels onlytext/image_url; LocalAI's server already acceptsimage_url,audio_url,video_url, andinput_audio— this closes the client-side gap.How
Three commits, TDD:
fragment.go— a typedMultimedia(MediaKind{Image,Audio,Video}+Data()/Format(); plainMultimediastays image, fully backward-compatible), aNativeParttype, a transientFragment.PendingNativeParts, and aNativePartsAwareinterface.AddMessageroutes image parts to the existingimage_urlMultiContentpath and audio/video parts toPendingNativeParts.clients/localai_client.go— a mutex-guarded native-parts stash (SetPendingNativeParts, satisfyingNativePartsAware);marshalRequestrebuilds the last message withinput_audio/video_urlparts when the stash is set (map-preserve, so every other request field and message is untouched);Asksets its stash from the Fragment. Send-once (the resultFragmentdrops pending parts) so a multi-MB blob isn't re-uploaded every turn; the stash is read-not-cleared so stream retries resend.tools.go—askWithStreamingandpickToolset the stash fresh from their Fragment via aNativePartsAwaretype-assert, covering the streaming response and tool-decision request paths leak-free (every request origin sets fresh from its Fragment, so no prior turn's audio leaks forward).Design notes
LLM/StreamingLLMsignature changes,GetMessages/OpenAIClient/Fragment.Messagesuntouched; non-LocalAI clients are unaffected (the type-assert simply misses).MultiContent(unchanged, cheap); audio/video are send-once (large blobs).input_audio {format,data}(base64),video_url {url}(data URI),image_url {url}.Testing
go test ./clients/and theTestAddMessage*/TestExecuteToolsStreamingSerializesNativeAudioroot tests pass;go build ./clients/ .andgo vetclean. (The pre-existingfragment_e2e_test.goneeds a live LLM and is not run here.)A whole-branch review caught — and this branch fixes — a subtle cross-cutting bug: the usage-counting wrapper applied inside
ExecuteToolsembeds theLLMinterface, which would have hiddenSetPendingNativePartsfrom the seams' type-assertion and silently dropped native parts on the streaming path. Fixed with a forwarding method on the wrapper plus a regression test that drives the real wrapped/streaming seam (verified RED without the forwarder, GREEN with).Consumes
Unblocks the nib multimodal-attachments work (nib's
ContentPartimplementsTypedMultimedia).🤖 Generated with Claude Code