Skip to content

Commit 096297e

Browse files
authored
Merge branch 'main' into kelly/keyedCaches
2 parents 90850bb + a691e73 commit 096297e

File tree

2 files changed

+12
-15
lines changed
  • src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/Components/Pages/Chat
  • test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Ollama_Qdrant.verified/aichatweb/aichatweb.Web/Components/Pages/Chat

2 files changed

+12
-15
lines changed

src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/Components/Pages/Chat/Chat.razor

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@
6262
chatSuggestions?.Clear();
6363
await chatInput!.FocusAsync();
6464

65-
@*#if (IsOllama)
66-
// Display a new response from the IChatClient, streaming responses
67-
// aren't supported because Ollama will not support both streaming and using Tools
68-
currentResponseCancellation = new();
69-
var response = await ChatClient.GetResponseAsync(messages, chatOptions, currentResponseCancellation.Token);
70-
71-
// Store responses in the conversation, and begin getting suggestions
72-
messages.AddMessages(response);
73-
#else*@
7465
// Stream and display a new response from the IChatClient
7566
var responseText = new TextContent("");
7667
currentResponseMessage = new ChatMessage(ChatRole.Assistant, [responseText]);
@@ -85,7 +76,6 @@
8576
// Store the final response in the conversation, and begin getting suggestions
8677
messages.Add(currentResponseMessage!);
8778
currentResponseMessage = null;
88-
@*#endif*@
8979
chatSuggestions?.Update(messages);
9080
}
9181

test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Ollama_Qdrant.verified/aichatweb/aichatweb.Web/Components/Pages/Chat/Chat.razor

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,20 @@
6262
chatSuggestions?.Clear();
6363
await chatInput!.FocusAsync();
6464

65-
// Display a new response from the IChatClient, streaming responses
66-
// aren't supported because Ollama will not support both streaming and using Tools
65+
// Stream and display a new response from the IChatClient
66+
var responseText = new TextContent("");
67+
currentResponseMessage = new ChatMessage(ChatRole.Assistant, [responseText]);
6768
currentResponseCancellation = new();
68-
var response = await ChatClient.GetResponseAsync(messages, chatOptions, currentResponseCancellation.Token);
69+
await foreach (var update in ChatClient.GetStreamingResponseAsync([.. messages], chatOptions, currentResponseCancellation.Token))
70+
{
71+
messages.AddMessages(update, filter: c => c is not TextContent);
72+
responseText.Text += update.Text;
73+
ChatMessageItem.NotifyChanged(currentResponseMessage);
74+
}
6975

70-
// Store responses in the conversation, and begin getting suggestions
71-
messages.AddMessages(response);
76+
// Store the final response in the conversation, and begin getting suggestions
77+
messages.Add(currentResponseMessage!);
78+
currentResponseMessage = null;
7279
chatSuggestions?.Update(messages);
7380
}
7481

0 commit comments

Comments
 (0)