You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/tutorials/ai-powered-group-chat/ai-powered-group-chat.md
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,9 +55,24 @@ await foreach (var completion in chatClient.CompleteChatStreamingAsync(messagesI
55
55
}
56
56
```
57
57
58
-
The chat history is managed by `GroupHistoryStore`, which stores messages for context. It includes both user and assistant messages to maintain conversation continuity.
58
+
### Maintaining context with history
59
+
60
+
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.
61
+
62
+
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.
63
+
64
+
```csharp
65
+
// Store message generated by AI-assistant in memory
@@ -74,17 +89,6 @@ if (totalCompletion.Length - lastSentTokenLength > 20)
74
89
}
75
90
```
76
91
77
-
### Maintaining context with history
78
-
79
-
The `GroupHistoryStore` class manages the chat history for each group. It stores both user and AI messages, ensuring that the conversation context is preserved across interactions. This context is crucial for generating coherent AI responses.
0 commit comments