You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
attach/upload: enhance file type detection with content sniffing and filename keywords #498
Follow-up to #497. Currently getProcessor() relies solely on file extension matching. When that fails, we plan to add a file-size heuristic as a fallback (reusing the existing logic from modelfile generate).
For future improvement, two additional heuristic strategies could make file type detection more accurate:
1. Content sniffing
Read the first few bytes of the file to determine if it's text or binary:
If the content looks like valid JSON/YAML/TOML → classify as config
If the content is binary → classify based on file size (weight vs code)
Could use net/http.DetectContentType or a simple UTF-8 validity check
These heuristics would reduce the cases where users need to manually specify --media-type and provide more accurate auto-detection than file size alone.
Is this still available to work on? On current main, attach/upload still uses extension matching and the size fallback. Would a small first PR that recognizes valid JSON in extensionless files be useful, keeping known extensions authoritative and leaving ambiguous files on the current fallback? I'd keep filename keywords and YAML/TOML detection out until their precedence is agreed. I've run the existing file-type tests locally; no implementation changes yet.
Following up on the above - still happy to take this. The narrow first step I had in mind: recognize valid JSON in extensionless files, keep known extensions authoritative, leave ambiguous files on the current fallback, and hold filename keywords and YAML/TOML detection until precedence is agreed. Would you prefer I just open that PR?
Activity
charan-rathore commentedon Nov 26, 2026
Is this still available to work on? On current main, attach/upload still uses extension matching and the size fallback. Would a small first PR that recognizes valid JSON in extensionless files be useful, keeping known extensions authoritative and leaving ambiguous files on the current fallback? I'd keep filename keywords and YAML/TOML detection out until their precedence is agreed. I've run the existing file-type tests locally; no implementation changes yet.
charan-rathore commentedon Dec 3, 2026
Following up on the above - still happy to take this. The narrow first step I had in mind: recognize valid JSON in extensionless files, keep known extensions authoritative, leave ambiguous files on the current fallback, and hold filename keywords and YAML/TOML detection until precedence is agreed. Would you prefer I just open that PR?