diff --git a/src/ketr-chat/src/App.tsx b/src/ketr-chat/src/App.tsx index 991a484..aab7fa9 100644 --- a/src/ketr-chat/src/App.tsx +++ b/src/ketr-chat/src/App.tsx @@ -204,14 +204,38 @@ const App = () => { } }, [conversation]); + // Set the snack pop-up and open it + const setSnack = useCallback((message: string, severity: SeverityType = "success") => { + setSnackMessage(message); + setSnackSeverity(severity); + setSnackOpen(true); + }, []); + // Set the initial chat history to "loading" or the welcome message if loaded. useEffect(() => { if (sessionId === undefined) { setConversation([loadingMessage]); } else { - setConversation([welcomeMessage]); + fetch(getConnectionBase(loc) + `/api/history/${sessionId}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .then(response => response.json()) + .then(data => { + console.log(`Session id: ${sessionId} -- history returned from server with ${data.length} entries`) + setConversation([ + welcomeMessage, + ...data + ]); + }) + .catch(error => { + console.error('Error generating session ID:', error); + setSnack("Unable to obtain chat history.", "error"); + }); } - }, [sessionId, setConversation]); + }, [sessionId, setConversation, loc, setSnack]); // Extract the sessionId from the URL if present, otherwise // request a sessionId from the server. @@ -265,13 +289,6 @@ const App = () => { fetchSystemPrompt(); }, [sessionId, serverSystemPrompt, setServerSystemPrompt, loc]); - // Set the snack pop-up and open it - const setSnack = useCallback((message: string, severity: SeverityType = "success") => { - setSnackMessage(message); - setSnackSeverity(severity); - setSnackOpen(true); - }, []); - // If the tools have not been set, fetch them from the server useEffect(() => { if (tools.length || sessionId === undefined) { @@ -479,7 +496,7 @@ const App = () => { type MessageList = Message[]; const onNew = async () => { - reset(["rags", "tools", "history", "system-prompt"], "New chat started."); + reset(["history"], "New chat started."); } const sendQuery = async () => { diff --git a/src/server.py b/src/server.py index 68a7491..c285336 100644 --- a/src/server.py +++ b/src/server.py @@ -630,7 +630,7 @@ class WebServer: final_message = {"role": "assistant", "content": reply, 'metadata': {"title": f"🛠️ Tool(s) used: {','.join(tools_used)}"}} else: final_message = {"role": "assistant", "content": reply} - + history.append(final_message) yield {"status": "done", "message": final_message} except Exception as e: