Skip to content

Commit 7b09acd

Browse files
committed
timeout and streaming
1 parent a61ca4a commit 7b09acd

File tree

1 file changed

+0
-58
lines changed
  • mongodb-rag-docs/src/components/ChatbotInterface

1 file changed

+0
-58
lines changed

mongodb-rag-docs/src/components/ChatbotInterface/index.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -280,64 +280,6 @@ export default function ChatbotInterface() {
280280
setIsLoading(false);
281281
}
282282
};
283-
284-
const handleSubmit = async (e) => {
285-
e.preventDefault();
286-
if (!input.trim()) return;
287-
288-
// Add user message
289-
const userMessage = { role: 'user', content: input };
290-
setMessages(msgs => [...msgs, userMessage]);
291-
setInput('');
292-
setIsLoading(true);
293-
setShowSampleQuestions(true);
294-
295-
// Try streaming first
296-
try {
297-
await handleStreamedChat(input, messages);
298-
} catch (error) {
299-
console.error('Streaming failed, falling back to regular chat:', error);
300-
301-
// Fallback to non-streaming implementation
302-
try {
303-
const response = await fetch('https://mongodb-rag-docs-backend.vercel.app/api/chat/sync', {
304-
method: 'POST',
305-
headers: { 'Content-Type': 'application/json' },
306-
body: JSON.stringify({
307-
query: input,
308-
sessionId: sessionId,
309-
history: !sessionId ? messages : undefined
310-
})
311-
});
312-
313-
const data = await response.json();
314-
315-
if (data.sessionId && !sessionId) {
316-
setSessionId(data.sessionId);
317-
}
318-
319-
setMessages(msgs => [
320-
...msgs,
321-
{
322-
role: 'assistant',
323-
content: data.answer,
324-
sources: data.sources
325-
}
326-
]);
327-
} catch (error) {
328-
console.error('Chat error:', error);
329-
setMessages(msgs => [
330-
...msgs,
331-
{
332-
role: 'assistant',
333-
content: 'Sorry, I encountered an error. Please try again later.'
334-
}
335-
]);
336-
}
337-
} finally {
338-
setIsLoading(false);
339-
}
340-
};
341283
const clearChat = () => {
342284
// Reset the chat
343285
setMessages([

0 commit comments

Comments
 (0)