Skip to content

[Frontend] Support image object in llm.chat #19635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 6, 2025

Conversation

sfeng33
Copy link
Contributor

@sfeng33 sfeng33 commented Jun 14, 2025

Purpose

Fix 17551

Test Plan

Unit test:

pytest tests/entrypoints/test_chat_utils.py

Manual test:
Run a multimodal llm chat with hardcoded image object

python examples/offline_inference/mistral-small.py simple --format hf

Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @sfeng33, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the capability to pass image objects directly within the multimodal message content for the llm.chat frontend API. Previously, only image URLs and image embeds were supported. This change addresses issue #17551 and provides a more flexible way to handle image inputs, particularly when the image is already available in memory as an object (like a PIL image).

Highlights

  • New Multimodal Part Type: I've added support for a new message content part type, "image", allowing users to pass image objects directly in the llm.chat API.
  • Parsing Logic: Implemented the necessary parsing logic in chat_utils.py to handle the new "image" type for both synchronous and asynchronous chat requests, storing the provided image object.
  • Test Coverage: Updated existing unit tests in test_chat_utils.py to include examples of using the new "image" type with a PIL image object, ensuring this new functionality is tested.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mergify mergify bot added the frontend label Jun 14, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for directly passing image objects (e.g., PIL.Image) in chat messages, extending the existing multimodal capabilities. The changes include adding new parsing logic for these image objects in both synchronous and asynchronous content parsers, updating relevant type definitions, and modifying tests to cover this new functionality. My review primarily focuses on enhancing type specificity for the new image object parameters to improve code clarity, maintainability, and type safety.

@DarkLight1337
Copy link
Member

Thanks for working on this, can you fix the pre-commit errors first?

Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

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

Can you update the documentation and example files to showcase this way of inputting images?

@DarkLight1337
Copy link
Member

Otherwise the implementation looks good to me. cc @Isotr0py @ywang96

"image_url": {
"url": image_url
}
"type": "image",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer to have

Suggested change
"type": "image",
"type": "image_pil",

given that we add image_embed

Copy link
Member

Choose a reason for hiding this comment

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

I think that HF format uses type: "image". Not 100% sure on whether it supports passing object at the same time like this though. cc @ywang96

Copy link
Member

Choose a reason for hiding this comment

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

image_pil isn't a valid object type in HF chat template: https://huggingface.co/docs/transformers/main/en/chat_templating_multimodal?sampling=list+of+image+frames#image-inputs.

But since we will update all image messages to {"type": "image"} in _parse_chat_message_content_part, I think it's OK to use image_pil here.

Copy link
Member

Choose a reason for hiding this comment

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

Let's go with image_pil then

Copy link
Member

Choose a reason for hiding this comment

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

image_pil is better IMO!

Copy link
Member

@ywang96 ywang96 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this and carrying #17919 to the finishing line! The code change is clean to me, but please also address the comments from other reviewers.

"image_url": {
"url": image_url
}
"type": "image",
Copy link
Member

Choose a reason for hiding this comment

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

image_pil is better IMO!

@mergify mergify bot added the documentation Improvements or additions to documentation label Jun 20, 2025
@sfeng33
Copy link
Contributor Author

sfeng33 commented Jun 20, 2025

Thank you all for the feedback!

Updates in this revision:

  • Replaced the type 'image' with 'image_pil'.
  • Added a usage example in mistral-small.py.

I didn’t update the documentation since the current docs don’t seem to cover this area. That said, I’m happy to add something if you have suggestions for a good place to include it.

@DarkLight1337
Copy link
Member

Would be great if you could update the documentation on this page! https://docs.vllm.ai/en/latest/features/multimodal_inputs.html

@sfeng33 sfeng33 requested a review from hmellor as a code owner July 1, 2025 06:40
@sfeng33
Copy link
Contributor Author

sfeng33 commented Jul 1, 2025

Addressed @DarkLight1337's feedback on documentation.

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) July 2, 2025 02:26
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 2, 2025
sfeng33 added 7 commits July 6, 2025 01:41
Signed-off-by: sfeng33 <[email protected]>
Signed-off-by: sfeng33 <[email protected]>
Signed-off-by: Flora Feng <[email protected]>
Signed-off-by: sfeng33 <[email protected]>
Signed-off-by: Flora Feng <[email protected]>
Signed-off-by: sfeng33 <[email protected]>
Signed-off-by: sfeng33 <[email protected]>
This reverts commit 4faa6cc.

Signed-off-by: sfeng33 <[email protected]>
sfeng33 added 4 commits July 6, 2025 01:41
Signed-off-by: Flora Feng <[email protected]>
Signed-off-by: sfeng33 <[email protected]>
Signed-off-by: sfeng33 <[email protected]>
Signed-off-by: sfeng33 <[email protected]>
Signed-off-by: sfeng33 <[email protected]>
auto-merge was automatically disabled July 6, 2025 01:45

Head branch was pushed to by a user without write access

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) July 6, 2025 02:15
@DarkLight1337 DarkLight1337 merged commit fe1e924 into vllm-project:main Jul 6, 2025
67 checks passed
@sfeng33 sfeng33 deleted the image branch July 6, 2025 06:54
huydhn pushed a commit to huydhn/vllm that referenced this pull request Jul 8, 2025
Chen-zexi pushed a commit to Chen-zexi/vllm that referenced this pull request Jul 13, 2025
patrickvonplaten pushed a commit to patrickvonplaten/vllm that referenced this pull request Jul 15, 2025
Signed-off-by: sfeng33 <[email protected]>
Signed-off-by: Flora Feng <[email protected]>
Signed-off-by: Patrick von Platen <[email protected]>
LyrisZhong pushed a commit to LyrisZhong/vllm that referenced this pull request Jul 23, 2025
avigny pushed a commit to avigny/vllm that referenced this pull request Jul 31, 2025
Signed-off-by: sfeng33 <[email protected]>
Signed-off-by: Flora Feng <[email protected]>
Signed-off-by: avigny <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation frontend ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support HF-style chat template for multi-modal data in offline chat
5 participants