-
Notifications
You must be signed in to change notification settings - Fork 555
.NET: Enable access to hosted AIAgents via OpenAI Chat Completions #1302
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
Conversation
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 support for OpenAI ChatCompletions protocol to enable access to hosted AI agents via the standard OpenAI API endpoints. The implementation supports both streaming and non-streaming chat completion requests as per the OpenAI specification.
- Maps OpenAI ChatCompletions endpoints via
MapOpenAIChatCompletions
extension method - Implements streaming and non-streaming chat completion responses using OpenAI SDK types
- Adds sample client demonstrating ChatCompletions protocol usage
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
EndpointRouteBuilderExtensions.Responses.cs | Updated class to partial and generalized documentation for multiple OpenAI protocols |
EndpointRouteBuilderExtensions.ChatCompletions.cs | New extension methods for mapping ChatCompletions endpoints to AI agents |
ChatCompletionsOptionsExtensions.cs | Utility class using reflection to access internal OpenAI SDK properties |
OpenAIChatCompletionsRunOptions.cs | Simple sealed class extending AgentRunOptions for ChatCompletions |
AIAgentChatCompletionsProcessor.cs | Core processor handling both streaming and non-streaming ChatCompletions requests |
Program.cs (AgentHost) | Registers ChatCompletions endpoints for sample agents |
Program.cs (Web) | Adds ChatCompletions client to dependency injection |
OpenAIChatCompletionsAgentClient.cs | Sample client implementation using OpenAI SDK to communicate via ChatCompletions protocol |
Home.razor | UI updates to support ChatCompletions protocol selection |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Description
Current PR provides the API to register custom endpoint to access the
AIAgent
via OpenAI ChatCompletions protocol:It supports the streaming and non-streaming chat completion request as per spec.
Because at the moment there is no API to restore the conversation/response/chat-completion, it does not support some of protocol APIs like get chat completion.
Implementation details
It is a similar PR to support of the OpenAI Responses protocol: #947.
I am using types defined in OpenAI SDK and using custom serialization implemented in the SDK itself. Also relying on the helpful MEAI extensions to convert input/output properly.
Validation
Here is the example of streaming events output (the most complicated scenario here):