Skip to content

fix: inject text-file content into chat completions messages - #9896

Merged
mudler merged 1 commit into
mudler:masterfrom
inquam:fix/file-attachment-content-not-sent
May 19, 2026
Merged

fix: inject text-file content into chat completions messages#9896
mudler merged 1 commit into
mudler:masterfrom
inquam:fix/file-attachment-content-not-sent

Conversation

@inquam

@inquam inquam commented May 19, 2026

Copy link
Copy Markdown
Contributor

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 as image_url content blocks and audio as audio_url content blocks, but the else branch (all other file types) only pushes metadata into userFiles it never adds the text content to messageContent. The files field on history messages is also not processed by the backend, so the content is lost on every turn.

Separately, Home.jsx's addFiles never calls file.text(), so textContent is always undefined for files attached from the home screen.

Fix

  • useChat.js: add a text content block to messageContent when file.textContent is present
  • Home.jsx: read textContent for non-image/non-audio files, matching the existing pattern in Chat.jsx's handleFileChange

Before

image

After

image

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.

  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
inquam force-pushed the fix/file-attachment-content-not-sent branch from baf0656 to 9cdf387 Compare May 19, 2026 19:02

@mudler mudler left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@mudler
mudler merged commit fc3980d into mudler:master May 19, 2026
55 checks passed
@localai-bot localai-bot added the bug Something isn't working label May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants