From f1556f2446df2a8dc48c282346c2b34ecccbb3e0 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 27 Jun 2023 17:53:46 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(chat):=20improve=20chat=20UI?= =?UTF-8?q?=20and=20add=20support=20for=20chat=20history=20display=20and?= =?UTF-8?q?=20sending=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modals/formModal/chatMessage/index.tsx | 235 +++++++++--------- src/frontend/src/modals/formModal/index.tsx | 67 ++++- 2 files changed, 179 insertions(+), 123 deletions(-) diff --git a/src/frontend/src/modals/formModal/chatMessage/index.tsx b/src/frontend/src/modals/formModal/chatMessage/index.tsx index 3d4ce0b44..a86f90a0e 100644 --- a/src/frontend/src/modals/formModal/chatMessage/index.tsx +++ b/src/frontend/src/modals/formModal/chatMessage/index.tsx @@ -31,136 +31,143 @@ export default function ChatMessage({ return (
- {!chat.isSend && ( -
- - -
- )} - {chat.isSend && ( - - )} -
- {!chat.isSend ? ( -
-
- {hidden && chat.thought && chat.thought !== "" && ( -
setHidden((prev) => !prev)} - className="absolute -top-1 -left-2 cursor-pointer" - > - -
- )} - {chat.thought && chat.thought !== "" && !hidden && ( -
setHidden((prev) => !prev)} - className=" text-start inline-block rounded-md text-gray-600 dark:text-gray-200 h-full border border-gray-300 dark:border-gray-500 +
+ {!chat.isSend && ( +
+ + +
+ )} + {chat.isSend && ( + + )} +
+ {!chat.isSend ? ( +
+
+ {hidden && chat.thought && chat.thought !== "" && ( +
setHidden((prev) => !prev)} + className="absolute -top-1 -left-2 cursor-pointer" + > + +
+ )} + {chat.thought && chat.thought !== "" && !hidden && ( +
setHidden((prev) => !prev)} + className=" text-start inline-block rounded-md text-background h-full border border-gray-300 dark:border-gray-500 bg-muted dark:bg-gray-800 w-[95%] pb-3 pt-3 px-2 ml-3 cursor-pointer scrollbar-hide overflow-scroll" - dangerouslySetInnerHTML={{ - __html: convert.toHtml(chat.thought), - }} - >
- )} - {chat.thought && chat.thought !== "" && !hidden &&

} -
-
-
- - ▍ - + dangerouslySetInnerHTML={{ + __html: convert.toHtml(chat.thought), + }} + >
+ )} + {chat.thought && chat.thought !== "" && !hidden &&

} +
+
+
+ + ▍ + + ); + } + + children[0] = (children[0] as string).replace( + "`▍`", + "▍" ); } - children[0] = (children[0] as string).replace( - "`▍`", - "▍" + const match = /language-(\w+)/.exec(className || ""); + + return !inline ? ( + + ) : ( + + {children} + ); - } - - const match = /language-(\w+)/.exec(className || ""); - - return !inline ? ( - - ) : ( - - {children} - - ); - }, - }} - > - {message} - -
- {chat.files && ( -
- {chat.files.map((file, index) => { - return ( -
- -
- ); - })} + }, + }} + > + {message} +
- )} + {chat.files && ( +
+ {chat.files.map((file, index) => { + return ( +
+ +
+ ); + })} +
+ )} +
-
- ) : ( -
-
- "), - }} - > + ) : ( +
+
+ "), + }} + > +
-
- )} + )} +
); } diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 3023cfa49..a2819241c 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -11,7 +11,15 @@ import { ChatMessageType } from "../../types/chat"; import ChatInput from "./chatInput"; import _ from "lodash"; -import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "../../components/ui/dialog"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "../../components/ui/dialog"; import { dark } from "@mui/material/styles/createPalette"; import { CODE_PROMPT_DIALOG_SUBTITLE } from "../../constants"; import { postValidateCode } from "../../controllers/API"; @@ -51,7 +59,7 @@ export default function FormModal({ }, [open]); useEffect(() => { id.current = flow.id; - console.log(tabsState[flow.id]) + console.log(tabsState[flow.id]); }, [flow.id]); var isStream = false; @@ -338,15 +346,56 @@ export default function FormModal({
-
-
- - -
+
-
- teste +
+
+ {chatHistory.length > 0 ? ( + chatHistory.map((c, i) => ( + + )) + ) : ( +
+ + 👋{" "} + + LangFlow Chat + + +
+
+ + Start a conversation and click the agent’s thoughts{" "} + + + {" "} + to inspect the chaining process. + +
+
+ )} +
+
+
+
+ +
+