-
Notifications
You must be signed in to change notification settings - Fork 646
.NET: Improve fidelity of OpenAI ChatCompletions Hosting #1785
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
base: main
Are you sure you want to change the base?
Conversation
...Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Converters/MessageContentPartConverter.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/ChatCompletionChoice.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AgentRunResponseExtensions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/CreateChatCompletion.cs
Outdated
Show resolved
Hide resolved
...et/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AIAgentChatCompletionsProcessor.cs
Outdated
Show resolved
Hide resolved
...et/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AIAgentChatCompletionsProcessor.cs
Outdated
Show resolved
Hide resolved
...et/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AIAgentChatCompletionsProcessor.cs
Outdated
Show resolved
Hide resolved
...Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Converters/MessageContentPartConverter.cs
Show resolved
Hide resolved
...Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Converters/MessageContentPartConverter.cs
Show resolved
Hide resolved
There was a problem hiding this 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 |
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/ChatCompletionsJsonContext.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/ChatCompletionsJsonContext.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/CompletionUsage.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/CompletionUsage.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/CompletionUsage.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/ChatCompletionChoice.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/ChatCompletionChoice.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AgentRunResponseExtensions.cs
Show resolved
Hide resolved
...et/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AIAgentChatCompletionsProcessor.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs
Outdated
Show resolved
Hide resolved
|
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. |
|
thanks for review Reuben, added tests similar to what we have in OpenAI Responses |
Motivation and Context
Contribution Checklist