Add assistant messages into context history.
This commit is contained in:
parent
2d5f6a2797
commit
254816136e
@ -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 () => {
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user