-
Couldn't load subscription status.
- Fork 840
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a3a3e6f
Add support for using ConversationID for AzureOpenAI and OpenAI
ViveliDuCh b3c4ccf
Address feedback from PR review
ViveliDuCh 67b8366
Address PR Feedback: Dynamically detect stateful or stateless chat cl…
ViveliDuCh 4f940e5
Fix whitespace formatting
ViveliDuCh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/ResponseClientHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using Microsoft.Extensions.AI; | ||
| using Aspire.OpenAI; | ||
| using OpenAI; | ||
|
|
||
| //namespace chat.aspire.Web; | ||
ViveliDuCh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ViveliDuCh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| namespace Microsoft.Extensions.Hosting; | ||
|
|
||
| public static class ResponseClientHelper | ||
ViveliDuCh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
|
|
||
ViveliDuCh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static ChatClientBuilder AddResponsesChatClient(this AspireOpenAIClientBuilder builder, string? deploymentName) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder, "builder"); | ||
|
|
||
| return builder.HostBuilder.Services.AddChatClient((IServiceProvider services) => CreateInnerChatClient(services, builder, deploymentName)); | ||
| } | ||
| private static IChatClient CreateInnerChatClient(IServiceProvider services, AspireOpenAIClientBuilder builder, string? deploymentName) | ||
| { | ||
| OpenAIClient openAIClient = builder.ServiceKey is null ? services.GetRequiredService<OpenAIClient>() : services.GetRequiredKeyedService<OpenAIClient>(builder.ServiceKey); | ||
|
|
||
| if (deploymentName is null) | ||
| { | ||
| deploymentName = "gpt-4o-mini"; | ||
| } | ||
ViveliDuCh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| IChatClient chatClient = openAIClient.GetOpenAIResponseClient(deploymentName).AsIChatClient(); | ||
|
|
||
| if (builder.DisableTracing) | ||
| { | ||
| return chatClient; | ||
| } | ||
|
|
||
| var loggerFactory = services.GetService<ILoggerFactory>(); | ||
| return new OpenTelemetryChatClient(chatClient, loggerFactory?.CreateLogger(typeof(OpenTelemetryChatClient))); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...hatweb.AzureOpenAI_Qdrant_Aspire.verified/aichatweb/aichatweb.Web/ResponseClientHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using Microsoft.Extensions.AI; | ||
| using Aspire.OpenAI; | ||
| using OpenAI; | ||
|
|
||
| //namespace chat.aspire.Web; | ||
| namespace Microsoft.Extensions.Hosting; | ||
ViveliDuCh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public static class ResponseClientHelper | ||
| { | ||
|
|
||
| public static ChatClientBuilder AddResponsesChatClient(this AspireOpenAIClientBuilder builder, string? deploymentName) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder, "builder"); | ||
|
|
||
| return builder.HostBuilder.Services.AddChatClient((IServiceProvider services) => CreateInnerChatClient(services, builder, deploymentName)); | ||
| } | ||
| private static IChatClient CreateInnerChatClient(IServiceProvider services, AspireOpenAIClientBuilder builder, string? deploymentName) | ||
| { | ||
| OpenAIClient openAIClient = builder.ServiceKey is null ? services.GetRequiredService<OpenAIClient>() : services.GetRequiredKeyedService<OpenAIClient>(builder.ServiceKey); | ||
|
|
||
| if (deploymentName is null) | ||
| { | ||
| deploymentName = "gpt-4o-mini"; | ||
| } | ||
|
|
||
| IChatClient chatClient = openAIClient.GetOpenAIResponseClient(deploymentName).AsIChatClient(); | ||
|
|
||
| if (builder.DisableTracing) | ||
| { | ||
| return chatClient; | ||
| } | ||
|
|
||
| var loggerFactory = services.GetService<ILoggerFactory>(); | ||
| return new OpenTelemetryChatClient(chatClient, loggerFactory?.CreateLogger(typeof(OpenTelemetryChatClient))); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.