-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Added article: SignalR with Open AI #33448
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
mikekistler
left a comment
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.
I don't think this content really works as a tutorial. This is more an explanation of the sample project. Can you move this down to the Samples section?
IEvangelist
left a comment
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.
A few nits
aspnetcore/tutorials/ai-powered-group-chat/ai-powered-group-chat.md
Outdated
Show resolved
Hide resolved
aspnetcore/tutorials/ai-powered-group-chat/ai-powered-group-chat.md
Outdated
Show resolved
Hide resolved
aspnetcore/tutorials/ai-powered-group-chat/ai-powered-group-chat.md
Outdated
Show resolved
Hide resolved
aspnetcore/tutorials/ai-powered-group-chat/ai-powered-group-chat.md
Outdated
Show resolved
Hide resolved
aspnetcore/tutorials/ai-powered-group-chat/ai-powered-group-chat.md
Outdated
Show resolved
Hide resolved
aspnetcore/tutorials/ai-powered-group-chat/ai-powered-group-chat.md
Outdated
Show resolved
Hide resolved
Rick-Anderson
left a comment
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.
Wow, this looks like a really great article. It just needs a little work and we can help you make the changes.
| We use OpenAI for generating intelligent, context-aware responses and SignalR for delivering the response to users in a group. You can find the complete code [in this repo](https://github.com/microsoft/SignalR-Samples-AI/tree/main/AIStreaming). | ||
|
|
||
| ## Dependencies | ||
| You can use either Azure OpenAI or OpenAI for this project. Make sure to update the `endpoint` and `key` in `appsetting.json`. `OpenAIExtensions` reads the configuration when the app starts and they are required to authenticate and use either service. |
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 needs to be
Update the endpoint and key in appsetting.json file as shown in the following code:
After this PR merges, we can move the code to a sample folder and display the appsetting.json with the changes highlighted.
@dotnet-policy-service agree company="Microsoft" |
I agree with both of Mike's points above. @BrennanConroy Then per Mike's point above, the content for that sample in this PR here (after another edit round which I will help with) would go in a README for the sample. It is more of a description of the sample, rather than a tutorial. Thoughts? |
|
@BrennanConroy, thoughts? See suggestion above. |
(I've been assigned to finish this up.) Thanks @mikekistler , you mentioned moving this down to the "Samples section" I assume you meant moving it down in the TOC menu to "Real-time apps > Samples " ...that points directly to the sample repo here. Were you thinking the content in this PR should move to the SignalR-samples repo, or were you envisioning sub links under the Real-time apps > Samples TOC? If the latter, then I will create two sub items to "Samples" in the TOC, one for the samples repo (and make it more clear that is where it points to) and another for this topic. Also, It is not clear to me if the intent was that the samples code for this topic stays in that repo. I'm unaware of the history on that. I'll assume it does rather than moving it to the sample to the SignalR-samples repo unless I hear otherwise. Thanks for any clarification. |
|
Moving this to the SignalR-samples repo was what I had in mind, but sadly that repo is archived now, so we probably need some other solution. I don't have any strong opinion on this -- only that we should differentiate tutorials and samples for the benefit of users. |
…at.md Will be pulling all commits into a new PR. Commiting suggestions here before that transfer starts. Co-authored-by: Luke Latham <[email protected]>
…at.md Co-authored-by: David Pine <[email protected]>
…at.md Co-authored-by: David Pine <[email protected]>
…at.md Co-authored-by: David Pine <[email protected]>
…at.md Co-authored-by: David Pine <[email protected]>
…at.md Co-authored-by: David Pine <[email protected]>
…at.md Co-authored-by: David Pine <[email protected]>
…at.md Co-authored-by: David Pine <[email protected]>
IEvangelist
left a comment
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.
Awesome! A few nits and FYIs, otherwise ![]()
| # [OpenAI](#tab/open-ai) | ||
| To build this application, you will need the following: | ||
| * ASP.NET Core: To create the web application and host the SignalR hub. | ||
| * [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server. | ||
| * [OpenAI Client](https://www.nuget.org/packages/OpenAI/2.0.0-beta.10): To interact with OpenAI's API for generating AI responses. | ||
|
|
||
| # [Azure OpenAI](#tab/azure-open-ai) | ||
| To build this application, you will need the following: | ||
| * ASP.NET Core: To create the web application and host the SignalR hub. | ||
| * [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server. | ||
| * [Azure OpenAI](https://www.nuget.org/packages/Azure.AI.OpenAI/2.0.0-beta.3): Azure.AI.OpenAI | ||
| --- |
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.
I believe the added space helps with readability...and not that it really matters, but I've found myself trying to avoid tabs with H1's, you're free to use any heading value so long as the #tab bookmark/syntax is in place. Also, removed versions from the packages as stable releases are now available. See microsoft/SignalR-Samples-AI#5, where I just did a PR to upgrade these in the source.
| # [OpenAI](#tab/open-ai) | |
| To build this application, you will need the following: | |
| * ASP.NET Core: To create the web application and host the SignalR hub. | |
| * [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server. | |
| * [OpenAI Client](https://www.nuget.org/packages/OpenAI/2.0.0-beta.10): To interact with OpenAI's API for generating AI responses. | |
| # [Azure OpenAI](#tab/azure-open-ai) | |
| To build this application, you will need the following: | |
| * ASP.NET Core: To create the web application and host the SignalR hub. | |
| * [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server. | |
| * [Azure OpenAI](https://www.nuget.org/packages/Azure.AI.OpenAI/2.0.0-beta.3): Azure.AI.OpenAI | |
| --- | |
| ### [OpenAI](#tab/open-ai) | |
| To build this application, you will need the following: | |
| * ASP.NET Core: To create the web application and host the SignalR hub. | |
| * [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server. | |
| * [OpenAI Client](https://www.nuget.org/packages/OpenAI): To interact with OpenAI's API for generating AI responses. | |
| ### [Azure OpenAI](#tab/azure-open-ai) | |
| To build this application, you will need the following: | |
| * ASP.NET Core: To create the web application and host the SignalR hub. | |
| * [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server. | |
| * [Azure OpenAI](https://www.nuget.org/packages/Azure.AI.OpenAI): `Azure.AI.OpenAI` | |
| --- |
|
|
||
| ### Data flow | ||
|
|
||
| :::image type="content" source="./sequence-diagram-ai-powered-group-chat.png" alt-text="sequence diagram for the AI-powered group chat"::: |
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.
Just an idea, not something that you need to do, but since we still do not have native support from the Learn platform for mermaid diagrams-I've been using mermaid.live and its share feature, that lets you encode/share diagrams. You can build this out, create the share, and embed the share as a comment in the Markdown (which hides it from the end user) but the content developer can use it as a source of truth for future edits, re-exporting it as an image to update the image itself.
For example:
<!--
https://mermaid.live/edit#pako:eNp1kk1P4zAQhv_KaK6botLQFnxAyhbt7mFRUQIXlMsQD6lFYmf9wVfV_752UyQQ4NPY7-N3xjPeYmMko0DH_wLrhi8UtZb6WkNcFLzRob9jO-4Hsl41aiDtoQJyUDUblqH7Si-S_lv5P-EOisYroz8zZWKuybYcYx7MZ2KdiLWNaZy35I2FX0F_47ZKbPEaLMPKuN44uPhZH7gKJufnP6AQcG1V27J143kxnpcCVhtuHhyY4EelM2aAS7IP0jwdTPYXJpPnUlQNabiP1dyUfw9OrOUHy7WAK3KO3TtmnaRJqqJkH6x2wI_UBUrvAcsudP5jXatoEmtVzjuQ5GkUJVNswSN5hgIz7Nn2pGQc4jbpNfoN91yjiKGMD6ix1rvIpWlWL7pB4W3gDK0J7QbFPXUu7sIQE7yN_w1hqWLPL8cvsv8pGcZeo9jiM4rl8uh0tjidneXzfDmbH88zfEGRnxxN48rzs3yaLxYn08Uuw1djounx_vbtPk4Jdv8Bo5TJ1A
-->Check out this link.
|
|
||
| The `CompleteChatStreamingAsync()` method streams responses from OpenAI incrementally, which allows the app to send partial responses to the client as they are generated. | ||
|
|
||
| The code uses a `StringBuilder` to accumulate the AI's response. It checks the length of the buffered content and sends it to the clients when it exceeds a certain threshold (e.g., 20 characters). This approach ensures that users see the AI’s response as it forms, mimicking a human-like typing effect. |
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.
| The code uses a `StringBuilder` to accumulate the AI's response. It checks the length of the buffered content and sends it to the clients when it exceeds a certain threshold (e.g., 20 characters). This approach ensures that users see the AI’s response as it forms, mimicking a human-like typing effect. | |
| The code uses a <xref:System.Text.StringBuilder> to accumulate the AI's response. It checks the length of the buffered content and sends it to the clients when it exceeds a certain threshold (e.g., 20 characters). This approach ensures that users see the AI’s response as it forms, mimicking a human-like typing effect. |
| id, | ||
| totalCompletion.ToString()); | ||
|
|
||
| lastSentTokenLength = totalCompletion.Length; |
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.
nit: This is something I don't like about bing chat, it sends the entire message every update. Really it should just append the new content on the client side, saves bandwidth and memory usage on the server.
|
Closing this PR since commits were merged through a new one. The commits here were moved into a new PR by request, which included all changes asked for at the time, plus some updates per review at #34848 and that merged after approval. However, I didn't realize that two more suggestions were made on this PR just before I merged to main.
|

Internal previews