Skip to content

Refactor mime type#254

Open
Prashidha Kharel (cool8137) wants to merge 4 commits intolangchain-ai:mainfrom
cool8137:refactor-mime-type
Open

Refactor mime type#254
Prashidha Kharel (cool8137) wants to merge 4 commits intolangchain-ai:mainfrom
cool8137:refactor-mime-type

Conversation

@cool8137
Copy link
Copy Markdown

@cool8137 Prashidha Kharel (cool8137) commented Mar 12, 2026

This PR refactors the mime type definition to make it easy to extend mime type in the future.

Problem

The image and file mime types were originally hard coded strings defined at different places. Extending supported filetype would require changes to be made at many places.

Solution

This PR centralises the definition of mime type by doing the following:

  • Define mime types in src/lib/multimodal-utils.ts as an enum like object MIME_TYPE.
  • Create define type guards for SupportedImageType and SupportedFileype.
  • Use the mime type object values and type guards whenever checking for mime type.
  • Add unit tests using vitest.

Testing

Two Unit test files have been added for the multimodal-utils and multipodal preview fiels.

Here is a screen shot of local usage of image upload which is working as expected.

image

I was inspired for this refactor when I was trying to add a new mime type for my personal project.

Although this PR is not linked to any existing issue, I hope it is small and useful enough to merge.

Let me know if you have any comments.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 12, 2026

Prashidha Kharel (@cool8137) is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant