Skip to content

Commit 4642d6d

Browse files
authored
Fixed issues reported by build tool
1 parent 7c9b7fe commit 4642d6d

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

articles/azure-signalr/signalr-tutorial-group-chat-with-open-ai.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,43 @@ title: Build an AI-Powered Group Chat with SignalR and OpenAI
33
author: kevinguo-ed
44
description: A tutorial explaining how SignalR and OpenAI are used together to build an AI-powered group chat
55
ms.author: kevinguo
6+
ms.topic: tutorial
67
ms.date: 09/09/2024
78
uid: tutorials/ai-powered-group-chat
89
---
910

11+
# Build an AI-powered group chat with SignalR and OpenAI
12+
1013
## Overview
1114

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"?
15+
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're exploring AI-powered apps in a team's context. They ask "what value can AI add to a team of collaborators?"
1316

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.
17+
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.
1518

1619
:::image type="content" source="./media/signalr-tutorial-group-chat-with-open-ai/ai-powered-group-chat.jpg" alt-text="user interface for the AI-powered group chat":::
1720

1821
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/aspnet/AzureSignalR-samples/tree/main/samples/AIStreaming).
1922

2023
## Dependencies
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.
24+
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're required to authenticate and use either service.
2225

2326
# [OpenAI](#tab/open-ai)
24-
To build this application, you will need the following:
25-
* ASP.NET Core: To create the web application and host the SignalR hub.
26-
* [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server.
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+
To build this application, you need the following:
28+
* ASP.NET Core: To create the web application and host the SignalR hub
29+
* [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server
30+
* [OpenAI Client](https://www.nuget.org/packages/OpenAI/2.0.0-beta.10): To interact with OpenAI's API for generating AI responses
2831

2932
# [Azure OpenAI](#tab/azure-open-ai)
30-
To build this application, you will need the following:
33+
To build this application, you need the following:
3134
* ASP.NET Core: To create the web application and host the SignalR hub.
32-
* [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server.
33-
* [Azure SignalR](https://learn.microsoft.com/azure/azure-signalr/signalr-overview): For managing SignalR connections at scale
35+
* [SignalR](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client): For real-time communication between clients and the server
36+
* [Azure SignalR](./signalr-overview.md): For managing SignalR connections at scale
3437
* [Azure OpenAI](https://www.nuget.org/packages/Azure.AI.OpenAI/2.0.0-beta.3): Azure.AI.OpenAI
3538
---
3639

3740
## Implementation
3841

39-
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.
42+
In this section, we walk through the key parts of the code that integrate SignalR with OpenAI to create an AI-enhanced group chat experience.
4043

4144
### Data flow
4245

@@ -58,7 +61,7 @@ await foreach (var completion in chatClient.CompleteChatStreamingAsync(messagesI
5861

5962
### Maintain context with history
6063

61-
Every request to [Open AI's Chat Completions API](https://platform.openai.com/docs/guides/chat-completions) is stateless - Open AI doesn't store past interactions. In a chat application, what a user or an assistant has said is important for generating a response that's contextually relevant. We can achieve this by including chat history in every request to the Completions API.
64+
Every request to [OpenAI's Chat Completions API](https://platform.openai.com/docs/guides/chat-completions) is stateless - OpenAI doesn't store past interactions. In a chat application, what a user or an assistant has said is important for generating a response that's contextually relevant. We can achieve this by including chat history in every request to the Completions API.
6265

6366
The `GroupHistoryStore` class manages chat history for each group. It stores messages posted by both the users and AI assistants, ensuring that the conversation context is preserved across interactions. This context is crucial for generating coherent AI responses.
6467

@@ -78,9 +81,9 @@ _history.GetOrAddGroupHistory(groupName, userName, message);
7881

7982
### Stream AI responses
8083

81-
The `CompleteChatStreamingAsync()` method streams responses from OpenAI incrementally, which allows the application to send partial responses to the client as they are generated.
84+
The `CompleteChatStreamingAsync()` method streams responses from OpenAI incrementally, which allows the application to send partial responses to the client as they're generated.
8285

83-
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.
86+
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 (for example, 20 characters). This approach ensures that users see the AI’s response as it forms, mimicking a human-like typing effect.
8487
```csharp
8588
totalCompletion.Append(content);
8689
if (totalCompletion.Length - lastSentTokenLength > 20)
@@ -93,6 +96,6 @@ if (totalCompletion.Length - lastSentTokenLength > 20)
9396
## Explore further
9497

9598
This project opens up exciting possibilities for further enhancement:
96-
1. **Advanced AI features**: Leverage other OpenAI capabilities like sentiment analysis, translation, or summarization.
97-
2. **Incorporating multiple AI agents**: You can introduce multiple AI agents with distinct roles or expertise areas within the same chat. For example, one agent might focus on text generation, the other provides image or audio generation. This can create a richer and more dynamic user experience where different AI agents interact seamlessly with users and each other.
99+
1. **Advanced AI features**: Use other OpenAI capabilities like sentiment analysis, translation, or summarization.
100+
2. **Incorporating multiple AI agents**: You can introduce multiple AI agents with distinct roles or expertise areas within the same chat. For example, one agent might focus on text generation and the other provides image or audio generation. This interaction can create a richer and more dynamic user experience where different AI agents interact seamlessly with users and each other.
98101
3. **Share chat history between server instances**: Implement a database layer to persist chat history across sessions, allowing conversations to resume even after a disconnect. Beyond SQL or NO SQL based solutions, you can also explore using a caching service like Redis. It can significantly improve performance by storing frequently accessed data, such as chat history or AI responses, in memory. This reduces latency and offloads database operations, leading to faster response times, particularly in high-traffic scenarios.

0 commit comments

Comments
 (0)