diff --git a/web/src/app/chat/ChatPage.tsx b/web/src/app/chat/ChatPage.tsx index aeb543af4..a8b4e570d 100644 --- a/web/src/app/chat/ChatPage.tsx +++ b/web/src/app/chat/ChatPage.tsx @@ -43,7 +43,7 @@ import { useContext, useEffect, useRef, useState } from "react"; import { usePopup } from "@/components/admin/connectors/Popup"; import { SEARCH_PARAM_NAMES, shouldSubmitOnLoad } from "./searchParams"; import { useDocumentSelection } from "./useDocumentSelection"; -import { useFilters } from "@/lib/hooks"; +import { useFilters, useLlmOverride } from "@/lib/hooks"; import { computeAvailableFilters } from "@/lib/filters"; import { FeedbackType } from "./types"; import ResizableSection from "@/components/resizable/ResizableSection"; @@ -62,13 +62,16 @@ import { SelectedDocuments } from "./modifiers/SelectedDocuments"; import { ChatFilters } from "./modifiers/ChatFilters"; import { AnswerPiecePacket, DanswerDocument } from "@/lib/search/interfaces"; import { buildFilters } from "@/lib/search/utils"; -import { Tabs } from "./sessionSidebar/constants"; import { SettingsContext } from "@/components/settings/SettingsProvider"; import Dropzone from "react-dropzone"; import { LLMProviderDescriptor } from "../admin/models/llm/interfaces"; import { checkLLMSupportsImageInput, getFinalLLM } from "@/lib/llm/utils"; import { InputBarPreviewImage } from "./images/InputBarPreviewImage"; import { Folder } from "./folders/interfaces"; +import { ChatInputBar } from "./input/ChatInputBar"; +import { ConfigurationModal } from "./modal/configuration/ConfigurationModal"; +import { useChatContext } from "@/components/context/ChatContext"; +import { UserDropdown } from "@/components/UserDropdown"; const MAX_INPUT_HEIGHT = 200; const TEMP_USER_MESSAGE_ID = -1; @@ -76,32 +79,26 @@ const TEMP_ASSISTANT_MESSAGE_ID = -2; const SYSTEM_MESSAGE_ID = -3; export function ChatPage({ - user, - chatSessions, - availableSources, - availableDocumentSets, - availablePersonas, - availableTags, - llmProviders, - defaultSelectedPersonaId, documentSidebarInitialWidth, - defaultSidebarTab, - folders, - openedFolders, + defaultSelectedPersonaId, }: { - user: User | null; - chatSessions: ChatSession[]; - availableSources: ValidSources[]; - availableDocumentSets: DocumentSet[]; - availablePersonas: Persona[]; - availableTags: Tag[]; - llmProviders: LLMProviderDescriptor[]; - defaultSelectedPersonaId?: number; // what persona to default to documentSidebarInitialWidth?: number; - defaultSidebarTab?: Tabs; - folders: Folder[]; - openedFolders: { [key: number]: boolean }; + defaultSelectedPersonaId?: number; }) { + const [configModalActiveTab, setConfigModalActiveTab] = useState< + string | null + >(null); + let { + user, + chatSessions, + availableSources, + availableDocumentSets, + availablePersonas, + llmProviders, + folders, + openedFolders, + } = useChatContext(); + const router = useRouter(); const searchParams = useSearchParams(); const existingChatIdRaw = searchParams.get("chatId"); @@ -145,6 +142,13 @@ export function ChatPage({ filterManager.setSelectedSources([]); filterManager.setSelectedTags([]); filterManager.setTimeRange(null); + // reset LLM overrides + llmOverrideManager.setLlmOverride({ + name: "", + provider: "", + modelName: "", + }); + llmOverrideManager.setTemperature(null); // remove uploaded files setCurrentMessageFileIds([]); @@ -386,6 +390,8 @@ export function ChatPage({ availableDocumentSets, }); + const llmOverrideManager = useLlmOverride(); + // state for cancelling streaming const [isCancelled, setIsCancelled] = useState(false); const isCancelledRef = useRef(isCancelled); @@ -592,9 +598,13 @@ export function ChatPage({ .map((document) => document.db_doc_id as number), queryOverride, forceSearch, + modelProvider: llmOverrideManager.llmOverride.name || undefined, modelVersion: - searchParams.get(SEARCH_PARAM_NAMES.MODEL_VERSION) || undefined, + llmOverrideManager.llmOverride.modelName || + searchParams.get(SEARCH_PARAM_NAMES.MODEL_VERSION) || + undefined, temperature: + llmOverrideManager.temperature || parseFloat(searchParams.get(SEARCH_PARAM_NAMES.TEMPERATURE) || "") || undefined, systemPromptOverride: @@ -767,6 +777,32 @@ export function ChatPage({ } }; + const handleImageUpload = (acceptedFiles: File[]) => { + const llmAcceptsImages = checkLLMSupportsImageInput( + ...getFinalLLM(llmProviders, livePersona) + ); + if (!llmAcceptsImages) { + setPopup({ + type: "error", + message: + "The current Assistant does not support image input. Please select an assistant with Vision support.", + }); + return; + } + + uploadFilesForChat(acceptedFiles).then(([fileIds, error]) => { + if (error) { + setPopup({ + type: "error", + message: error, + }); + } else { + const newFileIds = [...currentMessageFileIds, ...fileIds]; + setCurrentMessageFileIds(newFileIds); + } + }); + }; + // handle redirect if chat page is disabled // NOTE: this must be done here, in a client component since // settings are passed in via Context and therefore aren't @@ -779,9 +815,9 @@ export function ChatPage({ const retrievalDisabled = !personaIncludesRetrieval(livePersona); return ( <> -
+ {/*
-
+
*/} @@ -789,10 +825,6 @@ export function ChatPage({ @@ -830,35 +862,18 @@ export function ChatPage({ /> )} - {documentSidebarInitialWidth !== undefined ? ( - { - const llmAcceptsImages = checkLLMSupportsImageInput( - ...getFinalLLM(llmProviders, livePersona) - ); - if (!llmAcceptsImages) { - setPopup({ - type: "error", - message: - "The current Assistant does not support image input. Please select an assistant with Vision support.", - }); - return; - } + setConfigModalActiveTab(null)} + filterManager={filterManager} + selectedAssistant={livePersona} + setSelectedAssistant={onPersonaChange} + llmOverrideManager={llmOverrideManager} + /> - uploadFilesForChat(acceptedFiles).then(([fileIds, error]) => { - if (error) { - setPopup({ - type: "error", - message: error, - }); - } else { - const newFileIds = [...currentMessageFileIds, ...fileIds]; - setCurrentMessageFileIds(newFileIds); - } - }); - }} - noClick - > + {documentSidebarInitialWidth !== undefined ? ( + {({ getRootProps }) => ( <>
{/* */}
{livePersona && (
-
+
- {chatSessionId !== null && ( -
setSharingModalVisible(true)} - className="ml-auto mr-6 my-auto border-border border p-2 rounded cursor-pointer hover:bg-hover-light" - > - +
+ {chatSessionId !== null && ( +
setSharingModalVisible(true)} + className={` + my-auto + p-2 + rounded + cursor-pointer + hover:bg-hover-light + `} + > + +
+ )} + +
+
- )} +
)} @@ -1166,143 +1194,23 @@ export function ChatPage({
-
-
- {!retrievalDisabled && ( -
-
- {selectedDocuments.length > 0 ? ( - - ) : ( - - )} -
-
- )} - -
-
-
- {currentMessageFileIds.length > 0 && ( -
- {currentMessageFileIds.map((fileId) => ( -
- { - setCurrentMessageFileIds( - currentMessageFileIds.filter( - (id) => id !== fileId - ) - ); - }} - /> -
- ))} -
- )} -