diff --git a/src/frontend/src/modals/formModal/chatMessage/index.tsx b/src/frontend/src/modals/formModal/chatMessage/index.tsx
index 7395b0908..722365e0c 100644
--- a/src/frontend/src/modals/formModal/chatMessage/index.tsx
+++ b/src/frontend/src/modals/formModal/chatMessage/index.tsx
@@ -17,6 +17,7 @@ import {
AccordionItem,
AccordionTrigger,
} from "../../../components/ui/accordion";
+import { Badge } from "../../../components/ui/badge";
export default function ChatMessage({
chat,
@@ -29,6 +30,7 @@ export default function ChatMessage({
}) {
const convert = new Convert({ newline: true });
const [hidden, setHidden] = useState(true);
+ const [template, setTemplate] = useState(chat.template);
return (
-
+
Initial Prompt
-
- {Object.keys(chat.message)
- .filter((key) => key !== chat.chatKey)
- .map((key) => chat.message[key])}
+
+ {
+ // Make all the variables that are inside curly braces bold
+ template.split("\n").map((line, index) => {
+ const regex = /{([^}]+)}/g;
+ let match;
+ let parts = [];
+ let lastIndex = 0;
+ while ((match = regex.exec(line)) !== null) {
+ // Push text up to the match
+ if (match.index !== lastIndex) {
+ parts.push(line.substring(lastIndex, match.index));
+ }
+ // Push div with matched text
+ parts.push(
+
+
+
+
+ {match[1]}
+
+ {chat.message[match[1]] ? (
+
+ {chat.message[match[1]]}
+
+ ) : (
+ ""
+ )}
+
+
+
+ );
+ // Update last index
+ lastIndex = regex.lastIndex;
+ }
+ // Push text after the last match
+ if (lastIndex !== line.length) {
+ parts.push(line.substring(lastIndex));
+ }
+ return {parts}
;
+ })
+ }
diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx
index bf81814a1..eee866bb0 100644
--- a/src/frontend/src/modals/formModal/index.tsx
+++ b/src/frontend/src/modals/formModal/index.tsx
@@ -94,6 +94,7 @@ export default function FormModal({
message: string | Object,
isSend: boolean,
chatKey: string,
+ template?: string,
thought?: string,
files?: Array
) => {
@@ -103,6 +104,8 @@ export default function FormModal({
newChat.push({ message, isSend, files, thought, chatKey });
} else if (thought) {
newChat.push({ message, isSend, thought, chatKey });
+ } else if (template) {
+ newChat.push({ message, isSend, chatKey, template });
} else {
newChat.push({ message, isSend, chatKey });
}
@@ -175,6 +178,7 @@ export default function FormModal({
intermediate_steps?: string;
is_bot: boolean;
message: string;
+ template: string;
type: string;
chatKey: string;
files?: Array;
@@ -185,6 +189,7 @@ export default function FormModal({
? {
isSend: !chatItem.is_bot,
message: chatItem.message,
+ template: chatItem.template,
thought: chatItem.intermediate_steps,
files: chatItem.files,
chatKey: chatItem.chatKey,
@@ -192,6 +197,7 @@ export default function FormModal({
: {
isSend: !chatItem.is_bot,
message: chatItem.message,
+ template: chatItem.template,
thought: chatItem.intermediate_steps,
chatKey: chatItem.chatKey,
}
@@ -323,19 +329,6 @@ export default function FormModal({
ref.current.focus();
}
}, [open]);
- function formatMessage(inputs: any): string {
- if (inputs) {
- if (typeof inputs == "string") return inputs;
- // inputs is a object with the keys and values being input_keys and keysValue
- // so the formated message is a string with the keys and values separated by ": "
- let message = "";
- for (const [key, value] of Object.entries(inputs)) {
- message += `${key}: ${value}\n`;
- }
- return message;
- }
- return "";
- }
function sendMessage() {
if (chatValue !== "") {
@@ -345,7 +338,12 @@ export default function FormModal({
let inputs = tabsState[id.current].formKeysData.input_keys;
setChatValue("");
const message = inputs;
- addChatHistory(message, true, chatKey);
+ addChatHistory(
+ message,
+ true,
+ chatKey,
+ tabsState[flow.id].formKeysData.template
+ );
sendAll({
...reactFlowInstance.toObject(),
inputs: inputs,
diff --git a/src/frontend/src/modals/genericModal/index.tsx b/src/frontend/src/modals/genericModal/index.tsx
index f4edb586b..739bbdba5 100644
--- a/src/frontend/src/modals/genericModal/index.tsx
+++ b/src/frontend/src/modals/genericModal/index.tsx
@@ -55,7 +55,6 @@ export default function GenericModal({
const [myButtonText] = useState(buttonText);
const [myModalTitle] = useState(modalTitle);
const [myModalType] = useState(type);
- const [open, setOpen] = useState(true);
const [inputValue, setInputValue] = useState(value);
const [isEdit, setIsEdit] = useState(true);
const [wordsHighlightInvalid, setWordsHighlightInvalid] = useState([]);
@@ -66,7 +65,6 @@ export default function GenericModal({
const { closePopUp, setCloseEdit } = useContext(PopUpContext);
const ref = useRef();
function setModalOpen(x: boolean) {
- setOpen(x);
if (x === false) {
setCloseEdit("generic");
closePopUp();
@@ -138,7 +136,6 @@ export default function GenericModal({
.then((apiReturn) => {
if (apiReturn.data) {
setNodeClass(apiReturn.data.frontend_node);
- setModalOpen(closeModal);
let inputVariables = apiReturn.data.input_variables;
if (inputVariables.length === 0) {
diff --git a/src/frontend/src/types/chat/index.ts b/src/frontend/src/types/chat/index.ts
index 546408e65..2e7a65fdb 100644
--- a/src/frontend/src/types/chat/index.ts
+++ b/src/frontend/src/types/chat/index.ts
@@ -4,6 +4,7 @@ import { FlowType } from "../flow";
export type ChatType = { flow: FlowType; reactFlowInstance: ReactFlowInstance };
export type ChatMessageType = {
message: string | Object;
+ template?: string;
isSend: boolean;
thought?: string;
files?: Array<{ data: string; type: string; data_type: string }>;
diff --git a/src/frontend/src/types/tabs/index.ts b/src/frontend/src/types/tabs/index.ts
index 89ba5ef15..33acd1ee7 100644
--- a/src/frontend/src/types/tabs/index.ts
+++ b/src/frontend/src/types/tabs/index.ts
@@ -40,6 +40,7 @@ export type TabsState = {
[key: string]: {
isPending: boolean;
formKeysData: {
+ template?: string;
input_keys?: Object;
memory_keys?: Array;
handle_keys?: Array;