|
1 | 1 | --- |
2 | | -title: Building AI-Powered Group Chat with SignalR and OpenAI |
| 2 | +title: Build an AI-Powered Group Chat with SignalR and OpenAI |
3 | 3 | author: kevinguo-ed |
4 | | -description: ... |
5 | | -ms.author: ... |
| 4 | +description: A tutorial explaining how SignalR and OpenAI are used together to build an AI-powered group chat |
| 5 | +ms.author: kevinguo |
6 | 6 | ms.date: 08/27/2024 |
| 7 | +uid: tutorials/ai-powered-group-chat |
7 | 8 | --- |
8 | 9 |
|
9 | 10 | ## Overview |
10 | 11 |
|
11 | | -The integration of AI into applications is rapidly becoming a must-have for developers looking to help their users be more creative, productive and achieve their health goals. AI-powered features, such as intelligent chatbots, personalized recommendations, and contextual responses, add significant value to modern apps. The AI-powered apps that came out since Chat GPT captured our imagination are primarily between one user and one AI assistant. As developers get more comfortable with the capabilities of AI, they are exploring AI-powered apps in a team's context. They ask "what value can AI add to a team of collaborators"? |
| 12 | +The integration of AI into applications is rapidly becoming a must-have for developers looking to help their users be more creative, productive and achieve their health goals. AI-powered features, such as intelligent chatbots, personalized recommendations, and contextual responses, add significant value to modern apps. The AI-powered apps that came out since ChatGPT captured our imagination are primarily between one user and one AI assistant. As developers get more comfortable with the capabilities of AI, they are exploring AI-powered apps in a team's context. They ask "what value can AI add to a team of collaborators"? |
12 | 13 |
|
13 | 14 | This tutorial guides you through building a real-time group chat application. Among a group of human collaborators in a chat, there's an AI assistant which has access to the chat history and can be invited to help out by any collaborator when they start the message with `@gpt`. The finished app looks like this. |
14 | 15 |
|
15 | | -{{Chat interface missing...}} |
| 16 | +:::image type="content" source="./ai-powered-group-chat.jpg" alt-text="user interface for the AI-powered group chat"::: |
16 | 17 |
|
17 | | -We use Open AI 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). |
| 18 | +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). |
18 | 19 |
|
19 | 20 | ## Dependencies |
20 | | -You can use either Azure Open AI or Open AI 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. |
| 21 | +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. |
21 | 22 |
|
22 | | -# [Open AI](#tab/open-ai) |
| 23 | +# [OpenAI](#tab/open-ai) |
23 | 24 | To build this application, you will need the following: |
24 | 25 | * ASP.NET Core: To create the web application and host the SignalR hub. |
25 | 26 | * [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server. |
26 | 27 | * [OpenAI Client](https://www.nuget.org/packages/OpenAI/2.0.0-beta.10): To interact with OpenAI's API for generating AI responses. |
27 | 28 |
|
28 | | -# [Azure Open AI](#tab/azure-open-ai) |
| 29 | +# [Azure OpenAI](#tab/azure-open-ai) |
29 | 30 | To build this application, you will need the following: |
30 | 31 | * ASP.NET Core: To create the web application and host the SignalR hub. |
31 | 32 | * [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server. |
32 | | -* [Azure Open AI](https://www.nuget.org/packages/Azure.AI.OpenAI/2.0.0-beta.3): Azure.AI.OpenAI |
| 33 | +* [Azure OpenAI](https://www.nuget.org/packages/Azure.AI.OpenAI/2.0.0-beta.3): Azure.AI.OpenAI |
33 | 34 | --- |
34 | 35 |
|
35 | 36 | ## Implementation |
36 | 37 |
|
37 | 38 | In this section, we'll walk through the key parts of the code that integrate SignalR with OpenAI to create an AI-enhanced group chat experience. |
38 | 39 |
|
39 | | -### SignalR Hub integration** |
| 40 | +### Data flow |
| 41 | + |
| 42 | +:::image type="content" source="./sequence-diagram-ai-powered-group-chat.png" alt-text="sequence diagram for the AI-powered group chat"::: |
| 43 | + |
| 44 | +### SignalR Hub integration |
40 | 45 |
|
41 | 46 | The `GroupChatHub` class manages user connections, message broadcasting, and AI interactions. When a user sends a message starting with `@gpt`, the hub forwards it to OpenAI, which generates a response. The AI's response is streamed back to the group in real-time. |
42 | 47 | ```csharp |
@@ -80,7 +85,7 @@ public void UpdateGroupHistoryForAssistant(string groupName, string message) |
80 | 85 | } |
81 | 86 | ``` |
82 | 87 |
|
83 | | -### Explore further |
| 88 | +## Explore further |
84 | 89 |
|
85 | 90 | This project opens up exciting possibilities for further enhancement: |
86 | 91 | 1. **Advanced AI features**: Leverage other OpenAI capabilities like sentiment analysis, translation, or summarization. |
|
0 commit comments