Skip to content

Conversation

@DeagleGross
Copy link
Contributor

Motivation and Context

  1. Reuben has already done a fantastic job improving OpenAI Responses at .NET: Improve fidelity of OpenAI Responses hosting #1550. We need to do the same for ChatCompletions, and this is what I am doing here
  2. OpenAI SDK is not suitable for writing server-based (hosting) scenarios, so we need to completely go off this package. See .NET: implement own OpenAI type-model and remove OpenAI SDK as a dependency #1437

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings October 29, 2025 17:38
@DeagleGross DeagleGross self-assigned this Oct 29, 2025
@DeagleGross DeagleGross requested review from ReubenBond and stephentoub and removed request for Copilot October 29, 2025 17:39
Copilot AI review requested due to automatic review settings October 29, 2025 21:26
Copy link
Contributor

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 adds OpenAI ChatCompletions API support to the Microsoft.Agents.AI framework, enabling AI agents to be exposed via OpenAI-compatible chat completion endpoints. This complements the existing OpenAI Responses support.

  • Introduces new model classes for chat completion requests and responses compatible with OpenAI's API schema
  • Adds extension methods for configuring ChatCompletions support via dependency injection and endpoint routing
  • Implements request processing and response streaming capabilities for chat completion workflows

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
ServiceCollectionExtensions.cs Adds AddOpenAIChatCompletions method to configure JSON serialization options
HostApplicationBuilderExtensions.cs Adds host builder extension method for ChatCompletions registration
EndpointRouteBuilderExtensions.ChatCompletions.cs Implements endpoint mapping for ChatCompletions API with validation and routing
ChatCompletionsOptionsExtensions.cs Removed reflection-based utilities for accessing internal OpenAI SDK properties
MessageContentPart.cs Defines content part types (text, image, audio, file) for chat messages
MessageContent.cs Implements polymorphic message content supporting both strings and structured content arrays
CreateChatCompletion.cs Defines the request model for chat completion creation with comprehensive parameters
CompletionUsage.cs Models token usage statistics with detailed breakdowns
ChatCompletionRequestMessage.cs Defines polymorphic message types (developer, system, user, assistant, tool, function)
ChatCompletionChunk.cs Models streaming response chunks
ChatCompletionChoice.cs Defines choice structures in completion responses
ChatCompletion.cs Models non-streaming completion responses
MessageContentPartConverter.cs Converts between OpenAI message content parts and internal AI content types
ChatCompletionsJsonSerializerOptions.cs Configures JSON serialization settings
ChatCompletionsJsonContext.cs Defines source-generated JSON serialization context
AgentRunResponseExtensions.cs Converts agent responses to OpenAI completion format
AIAgentChatCompletionsProcessor.cs Processes chat completion requests and handles streaming responses
Program.cs Adds ChatCompletions configuration to sample application

@ReubenBond
Copy link
Member

I don't see any tests. We should have extensive testing to demonstrate conformance/compatibility and to prevent regressions. Eg, it's easy to make a mistake with JSON serialization, such as having enums serialized with the wrong string convention or union/polymorphic types having the wrong format.

@DeagleGross
Copy link
Contributor Author

thanks for review Reuben, added tests similar to what we have in OpenAI Responses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants