From 51dbff0dcb550fa2f705694aafc5c44bc70555e8 Mon Sep 17 00:00:00 2001 From: Timothy Carambat Date: Fri, 16 Feb 2024 14:50:40 -0800 Subject: [PATCH] Breakout Chat/Query mode as a workspace setting (#734) Remove useless icons in prompt bar Add chatMode column to workspaces that defaults to chat Add UI for toggle of chat mode with hint Update UI for workspace settings to match designs --- .../ChatContainer/PromptInput/index.jsx | 71 +------------------ .../WorkspaceChat/ChatContainer/index.jsx | 6 -- frontend/src/index.css | 4 ++ frontend/src/models/workspace.js | 4 +- frontend/src/models/workspaceThread.js | 3 +- .../ChatHistorySettings/index.jsx | 5 +- .../ChatSettings/ChatModeSelection/index.jsx | 57 +++++++++++++++ .../ChatSettings/ChatModelSelection/index.jsx | 7 +- .../ChatSettings/ChatPromptSettings/index.jsx | 2 +- .../ChatTemperatureSettings/index.jsx | 2 +- .../WorkspaceSettings/ChatSettings/index.jsx | 2 + .../SuggestedChatMessages/index.jsx | 8 +-- .../GeneralAppearance/VectorCount/index.jsx | 4 +- .../GeneralAppearance/WorkspaceName/index.jsx | 2 +- .../DocumentSimilarityThreshold/index.jsx | 2 +- .../MaxContextSnippets/index.jsx | 2 +- .../VectorDBIdentifier/index.jsx | 10 +-- server/endpoints/chat.js | 46 +++++------- server/models/workspace.js | 3 +- .../20240216214639_init/migration.sql | 2 + server/prisma/schema.prisma | 1 + 21 files changed, 105 insertions(+), 138 deletions(-) create mode 100644 frontend/src/pages/WorkspaceSettings/ChatSettings/ChatModeSelection/index.jsx create mode 100644 server/prisma/migrations/20240216214639_init/migration.sql diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx index 75316308..45193df5 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx @@ -1,21 +1,10 @@ -import { - Chats, - CircleNotch, - Gear, - PaperPlaneRight, - Quotes, -} from "@phosphor-icons/react"; +import { CircleNotch, PaperPlaneRight } from "@phosphor-icons/react"; import React, { useState, useRef } from "react"; -import ManageWorkspace, { - useManageWorkspaceModal, -} from "../../../Modals/MangeWorkspace"; -import useUser from "@/hooks/useUser"; import SlashCommandsButton, { SlashCommands, useSlashCommands, } from "./SlashCommands"; import { isMobile } from "react-device-detect"; -import { Tooltip } from "react-tooltip"; export default function PromptInput({ workspace, @@ -27,10 +16,8 @@ export default function PromptInput({ sendCommand, }) { const { showSlashCommand, setShowSlashCommand } = useSlashCommands(); - const { showing, showModal, hideModal } = useManageWorkspaceModal(); const formRef = useRef(null); const [_, setFocused] = useState(false); - const { user } = useUser(); const handleSubmit = (e) => { setFocused(false); @@ -100,24 +87,6 @@ export default function PromptInput({
- {user?.role !== "default" && ( -
- - -
- )} -
- {showing && ( - - )} -
- ); -} - -function ChatModeSelector({ workspace }) { - const STORAGE_KEY = `workspace_chat_mode_${workspace.slug}`; - const [chatMode, setChatMode] = useState( - window.localStorage.getItem(STORAGE_KEY) ?? "chat" - ); - - function toggleMode() { - const newChatMode = chatMode === "chat" ? "query" : "chat"; - setChatMode(newChatMode); - window.localStorage.setItem(STORAGE_KEY, newChatMode); - } - - const ModeIcon = chatMode === "chat" ? Chats : Quotes; - return ( -
- -
); } diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/index.jsx index 543d6105..8a99a62a 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/index.jsx @@ -77,9 +77,6 @@ export default function ChatContainer({ workspace, knownHistory = [] }) { await Workspace.threads.streamChat( { workspaceSlug: workspace.slug, threadSlug }, promptMessage.userMessage, - window.localStorage.getItem( - `workspace_chat_mode_${workspace.slug}` - ) ?? "chat", (chatResult) => handleChat( chatResult, @@ -93,9 +90,6 @@ export default function ChatContainer({ workspace, knownHistory = [] }) { await Workspace.streamChat( workspace, promptMessage.userMessage, - window.localStorage.getItem( - `workspace_chat_mode_${workspace.slug}` - ) ?? "chat", (chatResult) => handleChat( chatResult, diff --git a/frontend/src/index.css b/frontend/src/index.css index b9e6976d..2c437982 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -439,3 +439,7 @@ dialog::backdrop { .slide-up { animation: slideUp 0.3s ease-out forwards; } + +.input-label { + @apply text-[14px] font-bold text-white; +} diff --git a/frontend/src/models/workspace.js b/frontend/src/models/workspace.js index 3b31646d..d77e2ad5 100644 --- a/frontend/src/models/workspace.js +++ b/frontend/src/models/workspace.js @@ -73,11 +73,11 @@ const Workspace = { .catch(() => false); return result; }, - streamChat: async function ({ slug }, message, mode = "query", handleChat) { + streamChat: async function ({ slug }, message, handleChat) { const ctrl = new AbortController(); await fetchEventSource(`${API_BASE}/workspace/${slug}/stream-chat`, { method: "POST", - body: JSON.stringify({ message, mode }), + body: JSON.stringify({ message }), headers: baseHeaders(), signal: ctrl.signal, openWhenHidden: true, diff --git a/frontend/src/models/workspaceThread.js b/frontend/src/models/workspaceThread.js index 256ea496..f9fad317 100644 --- a/frontend/src/models/workspaceThread.js +++ b/frontend/src/models/workspaceThread.js @@ -77,7 +77,6 @@ const WorkspaceThread = { streamChat: async function ( { workspaceSlug, threadSlug }, message, - mode = "query", handleChat ) { const ctrl = new AbortController(); @@ -85,7 +84,7 @@ const WorkspaceThread = { `${API_BASE}/workspace/${workspaceSlug}/thread/${threadSlug}/stream-chat`, { method: "POST", - body: JSON.stringify({ message, mode }), + body: JSON.stringify({ message }), headers: baseHeaders(), signal: ctrl.signal, openWhenHidden: true, diff --git a/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatHistorySettings/index.jsx b/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatHistorySettings/index.jsx index 29083574..9d46bc3b 100644 --- a/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatHistorySettings/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatHistorySettings/index.jsx @@ -2,10 +2,7 @@ export default function ChatHistorySettings({ workspace, setHasChanges }) { return (
-