Update frontend/src/components/ChatInterface.jsx
Browse files
frontend/src/components/ChatInterface.jsx
CHANGED
@@ -166,36 +166,21 @@ const ChatInterface = ({
|
|
166 |
|
167 |
return;
|
168 |
}
|
169 |
-
|
170 |
-
|
171 |
-
accumulatedText.current += data.content;
|
172 |
-
|
173 |
-
if (accumulatedText.current.length >= updateThreshold || data.content.includes('\n')) {
|
174 |
-
setMessages(prev => {
|
175 |
-
const userMsg = prev.find(m => m.sender === 'user' && m.text === message);
|
176 |
-
const botMsg = prev.find(m => m.id === streamMessageId);
|
177 |
-
|
178 |
-
const updatedMessages = userMsg ? prev : [
|
179 |
-
...prev,
|
180 |
-
{ sender: 'user', text: message, id: `user-${Date.now()}` }
|
181 |
-
];
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
186 |
);
|
187 |
-
}
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
accumulatedText.current = ''; // Réinitialiser l'accumulateur
|
193 |
-
|
194 |
-
requestAnimationFrame(() => {
|
195 |
-
scrollToBottom();
|
196 |
-
});
|
197 |
-
}
|
198 |
-
}
|
199 |
else if (data.type === 'error') {
|
200 |
console.error("SSE Error received:", data.error);
|
201 |
setIsStreaming(false);
|
|
|
166 |
|
167 |
return;
|
168 |
}
|
169 |
+
if (data.content) {
|
170 |
+
fullText += data.content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
+
// Update immediately without accumulation
|
173 |
+
setMessages(prev => {
|
174 |
+
return prev.map(msg =>
|
175 |
+
msg.id === streamMessageId
|
176 |
+
? { ...msg, text: fullText }
|
177 |
+
: msg
|
178 |
);
|
179 |
+
});
|
180 |
+
|
181 |
+
// Ensure scroll
|
182 |
+
requestAnimationFrame(scrollToBottom);
|
183 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
else if (data.type === 'error') {
|
185 |
console.error("SSE Error received:", data.error);
|
186 |
setIsStreaming(false);
|