Skip to content

Commit

Permalink
[Security solution] Fix regenerate button with LangGraph (#188249)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic authored Jul 13, 2024
1 parent c299737 commit f72a321
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit f72a321

Please sign in to comment.