From 88e809e40cf9a7a50efe5f990c9523f46dd5094b Mon Sep 17 00:00:00 2001 From: sherifButt <90522472+sherifButt@users.noreply.github.com> Date: Thu, 21 Mar 2024 05:59:22 +0000 Subject: [PATCH] - linked settings with metaResponse Chat functionality --- .../Generic/Blocks/TitleBlock/index.jsx | 60 +++++++++++ .../src/components/WorkspaceChat/index.jsx | 32 +++--- .../FeatureSettings/EnableComponent/index.jsx | 29 +++++ .../EnableSystemPrompt/index.jsx | 0 .../MetaResponse/FeatureSettings/index.jsx | 100 ++++++++++++++++++ .../MetaResponse/InputsFeature/index.jsx | 18 ---- .../WorkspaceSettings/MetaResponse/index.jsx | 57 +++------- server/endpoints/workspaceMetaResponse.js | 4 + server/endpoints/workspaces.js | 11 ++ 9 files changed, 236 insertions(+), 75 deletions(-) create mode 100644 frontend/src/components/Generic/Blocks/TitleBlock/index.jsx create mode 100644 frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/EnableComponent/index.jsx rename frontend/src/pages/WorkspaceSettings/MetaResponse/{InputsFeature => FeatureSettings}/EnableSystemPrompt/index.jsx (100%) create mode 100644 frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/index.jsx delete mode 100644 frontend/src/pages/WorkspaceSettings/MetaResponse/InputsFeature/index.jsx diff --git a/frontend/src/components/Generic/Blocks/TitleBlock/index.jsx b/frontend/src/components/Generic/Blocks/TitleBlock/index.jsx new file mode 100644 index 00000000..8891b7f0 --- /dev/null +++ b/frontend/src/components/Generic/Blocks/TitleBlock/index.jsx @@ -0,0 +1,60 @@ +import Badge from "@/components/Generic/Badges/Badge"; +import React from "react"; + +export default function TitleBlock({ + content, // toggle content goes here + label, + description, + badge = false, + badgeLabel, + badgeAnimated, + badgeBg, + border, + bg, + Icon, + labelStyles, +}) { + const borderStyle = border ? "border border-gray-600 rounded-2xl p-4" : ""; + const backgroundStyle = bg ? "bg-black/10" : ""; + + return ( +
+
+
+
+
+ {Icon && } +
+
+ + {badge && ( + + )} +
+
+
+
+
+
+

+ {description} +

+
+ {content} +
+
+ ); +} diff --git a/frontend/src/components/WorkspaceChat/index.jsx b/frontend/src/components/WorkspaceChat/index.jsx index 1c31c7e6..de8b3d2c 100644 --- a/frontend/src/components/WorkspaceChat/index.jsx +++ b/frontend/src/components/WorkspaceChat/index.jsx @@ -6,6 +6,7 @@ import { useParams } from "react-router-dom"; import ModalWrapper from "../ModalWrapper"; import ChatContainer from "./ChatContainer"; import LoadingChat from "./LoadingChat"; +import MetaResponse from "@/models/metaResponse"; export default function WorkspaceChat({ loading, workspace }) { const { threadSlug = null } = useParams(); @@ -27,19 +28,26 @@ export default function WorkspaceChat({ loading, workspace }) { ? await Workspace.threads.chatHistory(workspace.slug, threadSlug) : await Workspace.chatHistory(workspace.slug); - // TODO: add conditional if dynamic input is enabled in the workspace by default is false // Append metadata to the chat history - if (isMetaInputs) { - chatHistory = chatHistory.map((message) => { - if (message.role === "assistant") { - const { remainingText, metaData } = extractMetaData( - message.content - ); - setCurrentInputMeta(metaData); - return { ...message, content: remainingText, metaData }; - } - return message; - }); + if (workspace?.metaResponse) { + let metaResponseSettings = await MetaResponse.getMetaResponseSettings( + workspace.slug + ); + + console.log("meta Response Settings:", metaResponseSettings); + if (Object.values(metaResponseSettings).some((settings) => settings.isEnabled) + ) { + chatHistory = chatHistory.map((message) => { + if (message.role === "assistant") { + const { remainingText, metaData } = extractMetaData( + message.content + ); + setCurrentInputMeta(metaData); + return { ...message, content: remainingText, metaData }; + } + return message; + }); + } } setHistory(chatHistory); diff --git a/frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/EnableComponent/index.jsx b/frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/EnableComponent/index.jsx new file mode 100644 index 00000000..a31da2dc --- /dev/null +++ b/frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/EnableComponent/index.jsx @@ -0,0 +1,29 @@ +import ToggleBlock from "@/components/Generic/Blocks/ToggleBlock"; + +export default function EnableComponent({ + component, + isEnabled, + description, + onToggle, + Icon, + content, + disabled, + bg, +}) { + return ( +
+ +
+ ); +} diff --git a/frontend/src/pages/WorkspaceSettings/MetaResponse/InputsFeature/EnableSystemPrompt/index.jsx b/frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/EnableSystemPrompt/index.jsx similarity index 100% rename from frontend/src/pages/WorkspaceSettings/MetaResponse/InputsFeature/EnableSystemPrompt/index.jsx rename to frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/EnableSystemPrompt/index.jsx diff --git a/frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/index.jsx b/frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/index.jsx new file mode 100644 index 00000000..d2711d82 --- /dev/null +++ b/frontend/src/pages/WorkspaceSettings/MetaResponse/FeatureSettings/index.jsx @@ -0,0 +1,100 @@ +import TextAreaBlock from "@/components/Generic/Blocks/TextAreaBlock"; +import EnableSystemPrompt from "./EnableSystemPrompt"; +import CheckBoxBlock from "@/components/Generic/Blocks/CheckBoxBlock"; +import TitleBlock from "@/components/Generic/Blocks/TitleBlock"; +import ToggleBlock from "@/components/Generic/Blocks/ToggleBlock"; +import TextArea from "@/components/Generic/Inputs/TextArea"; + +export default function FeatureSettings({ + workspace, + settings, + onUpdateSettings, +}) { + return ( +
+ + {settings.config.systemPrompt.isEnabled && ( + <> + + + + )} + +