Skip to content
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

.Net: Add support for ImageContent to use data URIs in ChatPromptParser so templates can use base64 encoded images. #8401

Conversation

MarceloAGG
Copy link
Contributor

@MarceloAGG MarceloAGG commented Aug 27, 2024

Motivation and Context

At present, including images in prompt templates using base64 data encoding is not possible. This limitation is due to ChatPromptParser.cs exclusively calling the ImageContent constructor that requires a URI, which leads to an InvalidOperationException. The change required is straightforward and the limitation has been discussed before, for example here. Closes #7150.

Description

The proposed trivial fix involves a simple check to determine if the content starts with data:, and if it does the ImageContent constructor that accepts a dataUri is utilized instead.

Contribution Checklist

…hat use base64 data encoding. This limitation arises from ChatPromptParser.cs only calling the ImageContent constructor requiring a Uri which results in an InvalidOperationException. The proposed fix involves a simple check to determine if the content starts with "data:", and if it does the ImageContent constructor that accepts a dataUri is utilized instead.
@MarceloAGG MarceloAGG requested a review from a team as a code owner August 27, 2024 19:20
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels Aug 27, 2024
@MarceloAGG
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Microsoft"

@RogerBarreto
Copy link
Member

@MarceloAGG Thanks for the contribution!

I liked the approach, suggest adding also a Concept sample of using this.

@MarceloAGG
Copy link
Contributor Author

Good suggestion @RogerBarreto, Concept sample added.

@markwallace-microsoft markwallace-microsoft added this pull request to the merge queue Aug 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 30, 2024
@RogerBarreto RogerBarreto added this pull request to the merge queue Aug 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 30, 2024
@markwallace-microsoft markwallace-microsoft added this pull request to the merge queue Aug 30, 2024
Merged via the queue into microsoft:main with commit 78289af Aug 30, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Ignite kernel.core kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

.Net: Is it possible to use binary image data with a handlebars template?
5 participants