Skip to content

Expose streaming conversion utility methods #6636

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Jul 21, 2025

We're already exposing the non-streaming response conversions. Expose the streaming ones as well.

Microsoft Reviewers: Open in CodeFlow

We're already exposing the non-streaming response conversions. Expose the streaming ones as well.
@Copilot Copilot AI review requested due to automatic review settings July 21, 2025 13:39
@stephentoub stephentoub requested a review from a team as a code owner July 21, 2025 13:39
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Jul 21, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR exposes streaming conversion utility methods for both OpenAI Chat and Responses APIs, mirroring the existing non-streaming conversion methods. The changes primarily add public extension methods to convert streaming OpenAI responses to Microsoft.Extensions.AI types.

  • Adds AsChatResponseUpdatesAsync methods to both chat and responses extension classes
  • Updates existing conversion methods to accept optional ChatOptions parameters
  • Modifies visibility of internal streaming conversion methods to support the new public APIs

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
MicrosoftExtensionsAIChatExtensions.cs Adds streaming chat completion conversion method and updates existing method signatures
MicrosoftExtensionsAIResponsesExtensions.cs Adds streaming response conversion method and updates existing method signatures
OpenAIChatClient.cs Changes visibility of streaming conversion method from private to internal
OpenAIResponsesChatClient.cs Refactors streaming logic and changes method visibility to support new public APIs
OpenAIConversionTests.cs Adds comprehensive tests for the new streaming conversion methods
Comments suppressed due to low confidence (2)

test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIConversionTests.cs:288

  • The test method AsChatResponse_ConvertsOpenAIResponse only validates null argument handling but doesn't test the actual conversion logic due to OpenAI library limitations. Consider using mocking or test doubles to provide meaningful test coverage.
        // The OpenAI library currently doesn't provide any way to create an OpenAIResponse instance,

test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIConversionTests.cs:297

  • The test method AsChatResponseUpdatesAsync_ConvertsOpenAIStreamingResponseUpdates only validates null argument handling but doesn't test the actual streaming conversion logic. Consider using mocking or test doubles to provide comprehensive test coverage for the streaming functionality.
        // The OpenAI library currently doesn't provide any way to create a StreamingResponseUpdate instance,

Comment on lines +497 to +500
internal static IEnumerable<ResponseItem> ToOpenAIResponseItems(IEnumerable<ChatMessage> inputs, ChatOptions? options)
{
_ = options; // currently unused

Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

The comment indicates that the options parameter is currently unused. Consider either implementing the options handling or removing the parameter if it's not needed yet.

Suggested change
internal static IEnumerable<ResponseItem> ToOpenAIResponseItems(IEnumerable<ChatMessage> inputs, ChatOptions? options)
{
_ = options; // currently unused
internal static IEnumerable<ResponseItem> ToOpenAIResponseItems(IEnumerable<ChatMessage> inputs)
{

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ai Microsoft.Extensions.AI libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant