-
Notifications
You must be signed in to change notification settings - Fork 839
Add support for using ConversationID for AzureOpenAI and OpenAI #6770
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 stateful conversations by implementing conversationID functionality in Microsoft.Extensions.AI.WebChatTemplate. The changes enable conversation state management by switching from GetChatClient to GetOpenAIResponseClient for OpenAI and AzureOpenAI providers while maintaining compatibility with providers that don't support the Responses interface.
- Switch from GetChatClient to GetOpenAIResponseClient for OpenAI/AzureOpenAI providers to enable conversationID support
- Implement conversation state management by tracking conversationID in chat options and updating it from streaming responses
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
Chat.razor | Updates streaming response handling to pass only user message when the conversation is stateful (conversationId not null), skipping the rest of the message history based on the conversationID. |
Program.cs | Replaces GetChatClient with GetOpenAIResponseClient/AddResponsesChatClient calls for the providers that support it. |
Note: Adds inline NoWarn directive to suppress OPENAI001 warnings.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...plates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/Components/Pages/Chat/Chat.razor
Outdated
Show resolved
Hide resolved
...ns.AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/ResponseClientHelper.cs
Outdated
Show resolved
Hide resolved
...ns.AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/ResponseClientHelper.cs
Outdated
Show resolved
Hide resolved
...aichatweb.AzureOpenAI_Qdrant_Aspire.verified/aichatweb/aichatweb.Web/ResponseClientHelper.cs
Outdated
Show resolved
Hide resolved
...ts/Snapshots/aichatweb.AzureOpenAI_Qdrant_Aspire.verified/aichatweb/aichatweb.Web/Program.cs
Outdated
Show resolved
Hide resolved
....AzureOpenAI_Qdrant_Aspire.verified/aichatweb/aichatweb.Web/Components/Pages/Chat/Chat.razor
Outdated
Show resolved
Hide resolved
...ns.AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/ResponseClientHelper.cs
Outdated
Show resolved
Hide resolved
4b8a752
to
b3c4ccf
Compare
@dotnet-policy-service agree company="Microsoft" |
...e.verified/aichatweb/aichatweb.Web/AspireOpenAIClientBuilderResponsesChatClientExtensions.cs
Outdated
Show resolved
Hide resolved
...tensions.AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/Program.Aspire.cs
Outdated
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.
Otherwise, LGTM!
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.
This is looking great! Just a few suggestions.
...Data/ChatWithCustomData-CSharp.Web/AspireOpenAIClientBuilderResponsesChatClientExtensions.cs
Outdated
Show resolved
Hide resolved
...src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/ChatWithCustomData-CSharp.Web.csproj.in
Outdated
Show resolved
Hide resolved
...plates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/Components/Pages/Chat/Chat.razor
Outdated
Show resolved
Hide resolved
...plates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/Components/Pages/Chat/Chat.razor
Outdated
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.
Talking with @stephentoub about this, we should consider another approach to these changes. The template should produce a project that handles both stateful and stateless conversations.
@ViveliDuCh / @jozkee - We can chat more about the implications of this different approach.
I believe something like what I suggested here should handle both cases. We only submit the a subset of the converstaion history if the latest response update specified a |
…ient at runtime, remove Aspire-specific workarounds, simplify template logic, and default to stateful API where supported.
Fixes #6313
Implement support for stateful conversations, enabling the use of
conversationId
in the Microsoft.Extensions.AI chat web template. Add backend logic to the template for dynamically selecting stateful or stateless chat clients at runtime, enabling use of experimental stateful APIs likeGetOpenAIResponseClient
for supporting providers (AzureOpenAI, OpenAI), and laying the groundwork for future provider support.Providers like Ollama and GitHubModels currently use the legacy, stateless
GetChatClient
due to lack of stateful API support.Note: Use
GetOpenAIResponseClient
only with providers that support it—namely AzureOpenAI and OpenAI. Avoid using it with Ollama and GitHubModels, which throw runtime errors due to lack of support for theResponseStreamingChatClient
interface.Microsoft Reviewers: Open in CodeFlow