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({
diff --git a/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatModeSelection/index.jsx b/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatModeSelection/index.jsx new file mode 100644 index 00000000..0b3bb3b7 --- /dev/null +++ b/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatModeSelection/index.jsx @@ -0,0 +1,57 @@ +import { useState } from "react"; +export default function ChatModeSelection({ workspace, setHasChanges }) { + const [chatMode, setChatMode] = useState(workspace?.chatMode || "chat"); + + return ( +
+ {chatMode === "chat" ? ( + <> + Chat will provide answers with the LLM's general knowledge{" "} + and document context that is + found. + > + ) : ( + <> + Query will provide answers{" "} + only if document context is + found. + > + )} +
@@ -44,7 +41,7 @@ export default function ChatModelSelection({ return (
diff --git a/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatTemperatureSettings/index.jsx b/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatTemperatureSettings/index.jsx index 56321162..bd2178a6 100644 --- a/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatTemperatureSettings/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/ChatSettings/ChatTemperatureSettings/index.jsx @@ -16,7 +16,7 @@ export default function ChatTemperatureSettings({ return (
diff --git a/frontend/src/pages/WorkspaceSettings/ChatSettings/index.jsx b/frontend/src/pages/WorkspaceSettings/ChatSettings/index.jsx index d1f5a501..3004b871 100644 --- a/frontend/src/pages/WorkspaceSettings/ChatSettings/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/ChatSettings/index.jsx @@ -7,6 +7,7 @@ import ChatModelSelection from "./ChatModelSelection"; import ChatHistorySettings from "./ChatHistorySettings"; import ChatPromptSettings from "./ChatPromptSettings"; import ChatTemperatureSettings from "./ChatTemperatureSettings"; +import ChatModeSelection from "./ChatModeSelection"; export default function ChatSettings({ workspace }) { const [settings, setSettings] = useState({}); @@ -48,6 +49,7 @@ export default function ChatSettings({ workspace }) { onSubmit={handleUpdate} className="w-1/2 flex flex-col gap-y-6" > + - - Suggested Chat Messages - + Suggested Chat Messages Customize the messages that will be suggested to your workspace users. @@ -105,9 +103,7 @@ export default function SuggestedChatMessages({ slug }) { return ( - - Suggested Chat Messages - + Suggested Chat Messages Customize the messages that will be suggested to your workspace users. diff --git a/frontend/src/pages/WorkspaceSettings/GeneralAppearance/VectorCount/index.jsx b/frontend/src/pages/WorkspaceSettings/GeneralAppearance/VectorCount/index.jsx index 898ab796..9a882875 100644 --- a/frontend/src/pages/WorkspaceSettings/GeneralAppearance/VectorCount/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/GeneralAppearance/VectorCount/index.jsx @@ -16,7 +16,7 @@ export default function VectorCount({ reload, workspace }) { if (totalVectors === null) return ( - Number of vectors + Number of vectors Total number of vectors in your vector database. @@ -27,7 +27,7 @@ export default function VectorCount({ reload, workspace }) { ); return ( - Number of vectors + Number of vectors Total number of vectors in your vector database. diff --git a/frontend/src/pages/WorkspaceSettings/GeneralAppearance/WorkspaceName/index.jsx b/frontend/src/pages/WorkspaceSettings/GeneralAppearance/WorkspaceName/index.jsx index 8b75977b..b7c7f30f 100644 --- a/frontend/src/pages/WorkspaceSettings/GeneralAppearance/WorkspaceName/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/GeneralAppearance/WorkspaceName/index.jsx @@ -2,7 +2,7 @@ export default function WorkspaceName({ workspace, setHasChanges }) { return ( - + Workspace Name diff --git a/frontend/src/pages/WorkspaceSettings/VectorDatabase/DocumentSimilarityThreshold/index.jsx b/frontend/src/pages/WorkspaceSettings/VectorDatabase/DocumentSimilarityThreshold/index.jsx index e627962e..122e1144 100644 --- a/frontend/src/pages/WorkspaceSettings/VectorDatabase/DocumentSimilarityThreshold/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/VectorDatabase/DocumentSimilarityThreshold/index.jsx @@ -5,7 +5,7 @@ export default function DocumentSimilarityThreshold({ return ( - + Document similarity threshold diff --git a/frontend/src/pages/WorkspaceSettings/VectorDatabase/MaxContextSnippets/index.jsx b/frontend/src/pages/WorkspaceSettings/VectorDatabase/MaxContextSnippets/index.jsx index ba3f4c4f..50477906 100644 --- a/frontend/src/pages/WorkspaceSettings/VectorDatabase/MaxContextSnippets/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/VectorDatabase/MaxContextSnippets/index.jsx @@ -2,7 +2,7 @@ export default function MaxContextSnippets({ workspace, setHasChanges }) { return ( - + Max Context Snippets diff --git a/frontend/src/pages/WorkspaceSettings/VectorDatabase/VectorDBIdentifier/index.jsx b/frontend/src/pages/WorkspaceSettings/VectorDatabase/VectorDBIdentifier/index.jsx index c57e7d4d..9140d7fc 100644 --- a/frontend/src/pages/WorkspaceSettings/VectorDatabase/VectorDBIdentifier/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/VectorDatabase/VectorDBIdentifier/index.jsx @@ -1,13 +1,9 @@ export default function VectorDBIdentifier({ workspace }) { return ( - - Vector database identifier - - - - {workspace?.slug} - + Vector database identifier + + {workspace?.slug} ); } diff --git a/server/endpoints/chat.js b/server/endpoints/chat.js index 756944be..a08b36e2 100644 --- a/server/endpoints/chat.js +++ b/server/endpoints/chat.js @@ -1,14 +1,10 @@ const { v4: uuidv4 } = require("uuid"); const { reqBody, userFromSession, multiUserMode } = require("../utils/http"); -const { Workspace } = require("../models/workspace"); const { validatedRequest } = require("../utils/middleware/validatedRequest"); const { WorkspaceChats } = require("../models/workspaceChats"); const { SystemSettings } = require("../models/systemSettings"); const { Telemetry } = require("../models/telemetry"); -const { - streamChatWithWorkspace, - VALID_CHAT_MODE, -} = require("../utils/chats/stream"); +const { streamChatWithWorkspace } = require("../utils/chats/stream"); const { ROLES, flexUserRoleValid, @@ -16,6 +12,7 @@ const { const { EventLogs } = require("../models/eventLogs"); const { validWorkspaceAndThreadSlug, + validWorkspaceSlug, } = require("../utils/middleware/validWorkspace"); const { writeResponseChunk } = require("../utils/helpers/chat/responses"); @@ -24,32 +21,21 @@ function chatEndpoints(app) { app.post( "/workspace/:slug/stream-chat", - [validatedRequest, flexUserRoleValid([ROLES.all])], + [validatedRequest, flexUserRoleValid([ROLES.all]), validWorkspaceSlug], async (request, response) => { try { const user = await userFromSession(request, response); - const { slug } = request.params; - const { message, mode = "query" } = reqBody(request); + const { message } = reqBody(request); + const workspace = response.locals.workspace; - const workspace = multiUserMode(response) - ? await Workspace.getWithUser(user, { slug }) - : await Workspace.get({ slug }); - - if (!workspace) { - response.sendStatus(400).end(); - return; - } - - if (!message?.length || !VALID_CHAT_MODE.includes(mode)) { + if (!message?.length) { response.status(400).json({ id: uuidv4(), type: "abort", textResponse: null, sources: [], close: true, - error: !message?.length - ? "Message is empty." - : `${mode} is not a valid mode.`, + error: !message?.length ? "Message is empty." : null, }); return; } @@ -95,7 +81,13 @@ function chatEndpoints(app) { } } - await streamChatWithWorkspace(response, workspace, message, mode, user); + await streamChatWithWorkspace( + response, + workspace, + message, + workspace?.chatMode, + user + ); await Telemetry.sendTelemetry("sent_chat", { multiUserMode: multiUserMode(response), LLMSelection: process.env.LLM_PROVIDER || "openai", @@ -137,20 +129,18 @@ function chatEndpoints(app) { async (request, response) => { try { const user = await userFromSession(request, response); - const { message, mode = "query" } = reqBody(request); + const { message } = reqBody(request); const workspace = response.locals.workspace; const thread = response.locals.thread; - if (!message?.length || !VALID_CHAT_MODE.includes(mode)) { + if (!message?.length) { response.status(400).json({ id: uuidv4(), type: "abort", textResponse: null, sources: [], close: true, - error: !message?.length - ? "Message is empty." - : `${mode} is not a valid mode.`, + error: !message?.length ? "Message is empty." : null, }); return; } @@ -202,7 +192,7 @@ function chatEndpoints(app) { response, workspace, message, - mode, + workspace?.chatMode, user, thread ); diff --git a/server/models/workspace.js b/server/models/workspace.js index 9cc142e7..92c2f9e3 100644 --- a/server/models/workspace.js +++ b/server/models/workspace.js @@ -18,6 +18,7 @@ const Workspace = { "similarityThreshold", "chatModel", "topN", + "chatMode", ], new: async function (name = null, creatorId = null) { @@ -59,7 +60,7 @@ const Workspace = { try { const workspace = await prisma.workspaces.update({ where: { id }, - data, + data, // TODO: strict validation on writables here. }); return { workspace, message: null }; } catch (error) { diff --git a/server/prisma/migrations/20240216214639_init/migration.sql b/server/prisma/migrations/20240216214639_init/migration.sql new file mode 100644 index 00000000..368782bc --- /dev/null +++ b/server/prisma/migrations/20240216214639_init/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "workspaces" ADD COLUMN "chatMode" TEXT DEFAULT 'chat'; diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index 55b469cf..77b25c8d 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -98,6 +98,7 @@ model workspaces { similarityThreshold Float? @default(0.25) chatModel String? topN Int? @default(4) + chatMode String? @default("chat") workspace_users workspace_users[] documents workspace_documents[] workspace_suggested_messages workspace_suggested_messages[]
Customize the messages that will be suggested to your workspace users.
Total number of vectors in your vector database.
diff --git a/frontend/src/pages/WorkspaceSettings/VectorDatabase/DocumentSimilarityThreshold/index.jsx b/frontend/src/pages/WorkspaceSettings/VectorDatabase/DocumentSimilarityThreshold/index.jsx index e627962e..122e1144 100644 --- a/frontend/src/pages/WorkspaceSettings/VectorDatabase/DocumentSimilarityThreshold/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/VectorDatabase/DocumentSimilarityThreshold/index.jsx @@ -5,7 +5,7 @@ export default function DocumentSimilarityThreshold({ return (
diff --git a/frontend/src/pages/WorkspaceSettings/VectorDatabase/MaxContextSnippets/index.jsx b/frontend/src/pages/WorkspaceSettings/VectorDatabase/MaxContextSnippets/index.jsx index ba3f4c4f..50477906 100644 --- a/frontend/src/pages/WorkspaceSettings/VectorDatabase/MaxContextSnippets/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/VectorDatabase/MaxContextSnippets/index.jsx @@ -2,7 +2,7 @@ export default function MaxContextSnippets({ workspace, setHasChanges }) { return (
diff --git a/frontend/src/pages/WorkspaceSettings/VectorDatabase/VectorDBIdentifier/index.jsx b/frontend/src/pages/WorkspaceSettings/VectorDatabase/VectorDBIdentifier/index.jsx index c57e7d4d..9140d7fc 100644 --- a/frontend/src/pages/WorkspaceSettings/VectorDatabase/VectorDBIdentifier/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/VectorDatabase/VectorDBIdentifier/index.jsx @@ -1,13 +1,9 @@ export default function VectorDBIdentifier({ workspace }) { return (
- {workspace?.slug} -
{workspace?.slug}