Skip to content

Commit 1f9a023

Browse files
committed
Show generating response... during streaming and hide Getting Started with Agents Using Azure AI Foundry whenever assistant and user balloon shown that can happen during chat history loading.
1 parent 3f813c1 commit 1f9a023

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/api/static/ChatClient.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ChatClient {
1212

1313
console.log("[ChatClient] Sending message:", message);
1414
this.ui.appendUserMessage(message);
15+
document.getElementById("generating-message").style.display = "block";
1516

1617
const postData = { message: message };
1718

@@ -48,6 +49,7 @@ class ChatClient {
4849
this.handleMessages(response.body);
4950

5051
} catch (error) {
52+
document.getElementById("generating-message").style.display = "none";
5153
if (error.name === 'AbortError') {
5254
console.log('[ChatClient] Fetch request aborted by user.');
5355
} else {
@@ -111,6 +113,7 @@ class ChatClient {
111113
messageDiv = this.ui.createAssistantMessageDiv();
112114
console.log("[ChatClient] Created new messageDiv for assistant.");
113115
}
116+
document.getElementById("generating-message").style.display = "none";
114117
this.ui.appendAssistantMessage(
115118
messageDiv,
116119
data.error.message || "An error occurred.",
@@ -142,6 +145,7 @@ class ChatClient {
142145
annotations = data.annotations;
143146
isStreaming = false;
144147
console.log("[ChatClient] Received completed message:", accumulatedContent);
148+
document.getElementById("generating-message").style.display = "none";
145149
} else {
146150
accumulatedContent += data.content;
147151
console.log("[ChatClient] Received streaming chunk:", data.content);

src/api/static/ChatUI.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ class ChatUI {
3333
return content;
3434
}
3535

36+
removePlaceholder() {
37+
// Remove placeholder message if it exists
38+
const placeholderWrapper = document.getElementById("placeholder-wrapper");
39+
if (placeholderWrapper) {
40+
placeholderWrapper.remove();
41+
}
42+
}
43+
3644
addCitationClickListener() {
3745
document.addEventListener('click', (event) => {
3846
if (event.target.classList.contains('file-citation')) {
@@ -118,6 +126,9 @@ class ChatUI {
118126
}
119127

120128
appendUserMessage(message) {
129+
// Remove the placeholder message
130+
this.removePlaceholder();
131+
121132
const userTemplateClone = this.userTemplate.content.cloneNode(true);
122133
userTemplateClone.querySelector(".message-content").textContent = message;
123134
this.targetContainer.appendChild(userTemplateClone);
@@ -164,12 +175,15 @@ class ChatUI {
164175
}
165176
}
166177

167-
createAssistantMessageDiv() {
178+
createAssistantMessageDiv() {
168179
const assistantTemplateClone = this.assistantTemplate.content.cloneNode(true);
169180
if (!assistantTemplateClone) {
170181
console.error("Failed to clone assistant template.");
171182
return null;
172183
}
184+
185+
// Remove the placeholder message
186+
this.removePlaceholder();
173187

174188
// Append the clone to the target container
175189
this.targetContainer.appendChild(assistantTemplateClone);

src/api/static/main.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ function initChat() {
1212
const form = document.getElementById("chat-form");
1313
const messageInput = document.getElementById("message");
1414
const targetContainer = document.getElementById("messages");
15-
const placeholderWrapper = document.getElementById("placeholder-wrapper");
1615

1716
form.addEventListener("submit", async function(e) {
1817
e.preventDefault();
1918

20-
// Remove placeholder message if it exists
21-
if (placeholderWrapper) {
22-
placeholderWrapper.remove();
23-
}
24-
2519
await chatClient.sendMessage("/chat", messageInput.value.trim());
2620
messageInput.value = "";
2721
});

src/api/templates/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
</div>
5353
</div>
5454

55+
<text id="generating-message" style="display:none">Generating response...</text>
5556
<div id="chat-area" class="text-light px-4 py-2 rounded-top text-dark d-flex flex-column justify-content-center background-user">
5657
<form id="chat-form" onsubmit="event.preventDefault();">
5758
<div class="input-group">

0 commit comments

Comments
 (0)