fix: inject text-file content into chat completions messages - #9896
Merged
mudler merged 1 commit intoMay 19, 2026
Conversation
Non-image/non-audio file attachments (txt, md, csv, json) were being stored in the 'files' metadata field but never added to the message content array sent to /v1/chat/completions. Images and audio correctly received content blocks; files did not. Fix: push a text content block into messageContent when textContent is present, matching the pattern used for image_url and audio_url. Also fixes Home.jsx addFiles which never called file.text() at all, meaning files attached on the home screen had empty textContent even before reaching useChat.js. Note: PDF files use file.text() which returns raw bytes rather than parsed text. Proper PDF support would require PDF.js or server-side extraction and is not part of this fix. Signed-off-by: Daniel Liljeberg <damien_@hotmail.com>
inquam
force-pushed
the
fix/file-attachment-content-not-sent
branch
from
May 19, 2026 19:02
baf0656 to
9cdf387
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.
Problem
When attaching a .txt, .md, .csv, or .json file in the chat UI, I noticed that the model never saw the file content. Images and audio worked correctly.
Root cause
In
useChat.js, the file-type loop correctly adds images asimage_urlcontent blocks and audio asaudio_urlcontent blocks, but theelsebranch (all other file types) only pushes metadata intouserFilesit never adds the text content tomessageContent. Thefilesfield on history messages is also not processed by the backend, so the content is lost on every turn.Separately,
Home.jsx'saddFilesnever callsfile.text(), sotextContentis always undefined for files attached from the home screen.Fix
useChat.js: add a text content block tomessageContentwhenfile.textContentis presentHome.jsx: readtextContentfor non-image/non-audio files, matching the existing pattern inChat.jsx'shandleFileChangeBefore
After
Limitations
PDF files use the browser's
file.text()which returns raw bytes, not parsed text. So proper PDF support would require something like PDF.js integration or server-side extraction. This is a known limitation and not addressed here.Testing
Attach a .txt or .md file in the chat, send a message asking the model to summarise it and the model should now see the content.