Skip to content

.Net: Support BinaryContent in OpenAI Connector #11644

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

Conversation

nkeenan38
Copy link
Contributor

Motivation and Context

The OpenAI Connector only supports TextContent, ImageContent, and AudioContent KernelContent types. However, the Chat Completion API supports uploading other file types encoded as a base64 string. This change leverages that behavior to add support for BinaryContent.

Description

This change adds support for BinaryContent KernelContent types by using ChatMessageContentPart.CreateFilePart to create the corresponding ChatMessageContentPart.

Contribution Checklist

@nkeenan38 nkeenan38 requested a review from a team as a code owner April 18, 2025 17:31
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Apr 18, 2025
@RogerBarreto
Copy link
Member

Hi @nkeenan38 Thanks for the contribution,

Please add one Integration Test and a Sample ensuring it works as expected and the file content is passed down to the API.

Concept Samples - Similar to this

https://github.com/microsoft/semantic-kernel/blob/9c9aec0d76fe2fd916185a5c08af714c5eafa8db/dotnet/samples/Concepts/ChatCompletion/OpenAI_ChatCompletionWithAudio.cs

Integration Tests - Similar to this:

public async Task ChatCompletionWithAudioInputAndOutputAsync()

@nkeenan38
Copy link
Contributor Author

@microsoft-github-policy-service agree

@nkeenan38 nkeenan38 force-pushed the openai-connector-binary-content branch from 153a362 to f0a5119 Compare April 21, 2025 12:19
Copy link
Member

@RogerBarreto RogerBarreto left a comment

Choose a reason for hiding this comment

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

LGTM, just need some extra tests

@nkeenan38 nkeenan38 force-pushed the openai-connector-binary-content branch from fb69f2b to 7895d54 Compare April 22, 2025 13:25
@nkeenan38 nkeenan38 requested a review from RogerBarreto April 22, 2025 14:15
@nkeenan38 nkeenan38 force-pushed the openai-connector-binary-content branch from 7895d54 to 5cad4b3 Compare April 22, 2025 14:55
@RogerBarreto RogerBarreto moved this from Community PRs to Sprint: In Review in Semantic Kernel Apr 23, 2025
Copy link
Member

@RogerBarreto RogerBarreto left a comment

Choose a reason for hiding this comment

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

@nkeenan38 Thanks for addressing all feedback and putting forward this PR.

All looks good to me.

@markwallace-microsoft markwallace-microsoft added this pull request to the merge queue Apr 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 24, 2025
@RogerBarreto RogerBarreto added this pull request to the merge queue Apr 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 24, 2025
@RogerBarreto RogerBarreto added this pull request to the merge queue Apr 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 24, 2025
@RogerBarreto RogerBarreto added this pull request to the merge queue Apr 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 24, 2025
@RogerBarreto RogerBarreto added this pull request to the merge queue Apr 25, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 25, 2025
@RogerBarreto RogerBarreto added this pull request to the merge queue Apr 26, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 26, 2025
@RogerBarreto RogerBarreto added this pull request to the merge queue Apr 29, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 29, 2025
@RogerBarreto RogerBarreto added this pull request to the merge queue Apr 30, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Apr 30, 2025
@RogerBarreto RogerBarreto added this pull request to the merge queue May 1, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 1, 2025
@RogerBarreto RogerBarreto enabled auto-merge May 1, 2025 12:19
@RogerBarreto RogerBarreto added this pull request to the merge queue May 1, 2025
Merged via the queue into microsoft:main with commit 96963b4 May 1, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from Sprint: In Review to Sprint: Done in Semantic Kernel May 1, 2025
glorious-beard pushed a commit to glorious-beard/semantic-kernel that referenced this pull request May 6, 2025
The OpenAI Connector only supports `TextContent`, `ImageContent`, and
`AudioContent` KernelContent types. However, the Chat Completion API
supports uploading other file types encoded as a base64 string. This
change leverages that behavior to add support for `BinaryContent`.

This change adds support for `BinaryContent` KernelContent types by
using `ChatMessageContentPart.CreateFilePart` to create the
corresponding `ChatMessageContentPart`.

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation 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.

4 participants