[Security solution] Fix regenerate button with LangGraph (#188249)

This commit is contained in:
Steph Milovic 2024-07-13 08:16:12 -06:00 committed by GitHub
parent c2997378d4
commit f72a321a9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -49,6 +49,19 @@ export const persistConversationChanges = async ({
});
}
const lastMessage = state.conversation.messages
? state.conversation.messages[state.conversation.messages.length - 1]
: undefined;
if (lastMessage && lastMessage.content === state.input && lastMessage.role === 'user') {
// this is a regenerated message, do not update the conversation again
const langChainMessages = getLangChainMessages(state.conversation.messages ?? []);
const messages = langChainMessages.slice(0, -1); // all but the last message
return {
conversation: state.conversation,
messages,
};
}
const updatedConversation = await conversationsDataClient?.appendConversationMessages({
existingConversation: conversation ? conversation : state.conversation,
messages: [