Skip to content

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Jul 18, 2025

Fixes #6626

Microsoft Reviewers: Open in CodeFlow

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 fixes an issue with handling multiple response messages from the OpenAI Response API. The fix addresses a bug where multiple response messages with different IDs were being merged into a single message instead of being treated as separate messages.

  • Adds logic to detect when a new message with a different ID should create a separate ChatMessage instance
  • Removes a redundant property assignment that was adding the message ID to AdditionalProperties
  • Includes comprehensive test coverage for the multiple response messages scenario

Reviewed Changes

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

File Description
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponseChatClient.cs Adds logic to create new ChatMessage instances when processing multiple response messages with different IDs
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientTests.cs Adds test case to verify correct handling of multiple output messages in non-streaming scenarios

@stephentoub stephentoub enabled auto-merge (squash) July 18, 2025 03:04
@stephentoub stephentoub merged commit 29065e7 into dotnet:main Jul 18, 2025
7 checks passed
This was referenced Aug 13, 2025
This was referenced Aug 15, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-ai Microsoft.Extensions.AI libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error Message: System.ArgumentException : An item with the same key has already been added. Key: Id
2 participants