From 27137f1cdd3e5b88d76a9f3309352ae1a98597de Mon Sep 17 00:00:00 2001 From: "Debanjum (aider)" Date: Thu, 7 Nov 2024 15:14:02 -0800 Subject: [PATCH] Enable regenerating Khoj messages on web app - Replace Delete button with Regenerate button in chatMessage component - Update chat API to delete previous conversation with turn id, if exists --- .../components/chatMessage/chatMessage.tsx | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/interface/web/app/components/chatMessage/chatMessage.tsx b/src/interface/web/app/components/chatMessage/chatMessage.tsx index d05d9829..ec1e4062 100644 --- a/src/interface/web/app/components/chatMessage/chatMessage.tsx +++ b/src/interface/web/app/components/chatMessage/chatMessage.tsx @@ -30,6 +30,7 @@ import { Code, Shapes, Trash, + ArrowClockwise, } from "@phosphor-icons/react"; import DOMPurify from "dompurify"; @@ -682,6 +683,32 @@ const ChatMessage = forwardRef((props, ref) => } }; + const regenerateMessage = async (message: SingleChatMessage) => { + const turnId = message.turnId || props.turnId; + if (!message.rawQuery) return; + + const response = await fetch("/api/chat", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + q: message.rawQuery, + conversation_id: props.conversationId, + turn_id: turnId, + stream: false, + }), + }); + + if (response.ok) { + const result = await response.json(); + // Update the UI after successful regeneration + props.onDeleteMessage(turnId); + } else { + console.error("Failed to regenerate message"); + } + }; + const allReferences = constructAllReferences( props.chatMessage.context, props.chatMessage.onlineContext, @@ -744,7 +771,7 @@ const ChatMessage = forwardRef((props, ref) => /> ))} - {props.chatMessage.turnId && ( + {props.chatMessage.by === "you" && props.chatMessage.turnId && ( )} + {props.chatMessage.by === "khoj" && props.chatMessage.turnId && ( + + )}