diff --git a/client/components/UploadDocumentsForm.tsx b/client/components/UploadDocumentsForm.tsx deleted file mode 100644 index de032ac2..00000000 --- a/client/components/UploadDocumentsForm.tsx +++ /dev/null @@ -1,47 +0,0 @@ -"use client"; - -import { useState, type FormEvent } from "react"; -import DEFAULT_RETRIEVAL_TEXT from "@/data/DefaultRetrievalText"; - -export function UploadDocumentsForm() { - const [isLoading, setIsLoading] = useState(false); - const [document, setDocument] = useState(DEFAULT_RETRIEVAL_TEXT); - const ingest = async (e: FormEvent) => { - e.preventDefault(); - setIsLoading(true); - const response = await fetch("/api/retrieval/ingest", { - method: "POST", - body: JSON.stringify({ - text: document - }) - }); - if (response.status === 200) { - setDocument("Uploaded!"); - } else { - const json = await response.json(); - if (json.error) { - setDocument(json.error); - } - } - setIsLoading(false); - }; - return ( -
- - -
- ); -} \ No newline at end of file diff --git a/client/components/chat/ChatMessageBubble.tsx b/client/components/chat/ChatMessageBubble.tsx deleted file mode 100644 index ce5b41ea..00000000 --- a/client/components/chat/ChatMessageBubble.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { Avatar } from '@nextui-org/react'; -import type { Message } from 'ai/react'; -import AudioPlayer from './AudioPlayer'; - -export function ChatMessageBubble(props: { - message: Message; - sources: any[]; - aiAvatar?: string; - aiName?: string; - voice?: string; -}) { - const { voice = null } = props; - const colorClassName = - props.message.role === 'user' ? 'bg-[#d2e3fc]' : 'bg-slate-50 text-black'; - const alignmentClassName = - props.message.role === 'user' ? 'ml-auto' : 'mr-auto'; - const isBot = props.message.role === 'user' ? false : true; - return ( -
- {isBot && ( - - )} -
-
- {props.message.content} - {voice && isBot && ( - - )} -
-
-
- ); -} diff --git a/client/components/chat/ChatWindow.tsx b/client/components/chat/ChatWindow.tsx deleted file mode 100644 index e5bced90..00000000 --- a/client/components/chat/ChatWindow.tsx +++ /dev/null @@ -1,231 +0,0 @@ -'use client'; -import { ToastContainer, toast } from 'react-toastify'; -import 'react-toastify/dist/ReactToastify.css'; -import { useRef, useState, ReactElement, useCallback } from 'react'; -import type { FormEvent } from 'react'; -import { ChatMessageBubble } from '@/components/chat/ChatMessageBubble'; -import { UploadDocumentsForm } from '@/components/UploadDocumentsForm'; -import { IntermediateStep } from './IntermediateStep'; -import { useChat } from '@/app/hooks/useChat'; -import { Avatar } from '@nextui-org/react'; -import BotInfoCard from '../BotInfoCard'; -import AppendixIcon from '@/public/icons/AppendixIcon'; -import { ToolsCheck } from './ToolsCheck'; -import { ImgItem } from './ImgItem'; - -export function ChatWindow(props: { - endpoint: string; - botId?: string; - emptyStateComponent?: ReactElement; - placeholder?: string; - titleText?: string; - avatar?: string; - name?: string; - showIngestForm?: boolean; - showIntermediateStepsToggle?: boolean; - prompt?: string; - description?: string; - starters?: string[]; - streamming?: boolean; - loading?: boolean; - enableImgGeneration?: boolean; - voice?: string; -}) { - const messageContainerRef = useRef(null); - - const { - endpoint, - emptyStateComponent, - placeholder, - titleText, - showIngestForm, - showIntermediateStepsToggle, - avatar, - description, - starters, - name, - loading = false, - prompt, - botId, - enableImgGeneration, - voice, - } = props; - - const [showIntermediateSteps, setShowIntermediateSteps] = useState(true); - const ingestForm = showIngestForm && ( - - ); - const intemediateStepsToggle = showIntermediateStepsToggle && ( -
- setShowIntermediateSteps(e.target.checked)} - > - -
- ); - - const [sourcesForMessages, setSourcesForMessages] = useState< - Record - >({}); - - const { - messages, - input, - setInput, - handleInputChange, - handleSubmit, - isLoading: chatEndpointIsLoading, - stop, - } = useChat({ - api: endpoint, - onError: (e) => { - toast(e.message, { - theme: 'light', - }); - }, - }); - - const handleKeydown = useCallback( - (ev: React.KeyboardEvent) => { - if (ev.key === 'Enter') { - ev.preventDefault(); - handleSubmit({ - botId, - prompt, - enableImgGeneration, - show_intermediate_steps: true, - }); - } - }, - [handleSubmit, prompt, enableImgGeneration], - ); - - const welcomeComponent = emptyStateComponent ?? ( - - ); - - const sendMessage = useCallback( - (e: FormEvent) => { - e.preventDefault(); - setInput(''); - if (!chatEndpointIsLoading) { - return handleSubmit({ - prompt, - enableImgGeneration, - show_intermediate_steps: true, - }); - } - stop(); - }, - [chatEndpointIsLoading, handleSubmit, prompt, stop, enableImgGeneration], - ); - - return ( -
-

{titleText}

-

0 ? '' : 'hidden' - } text-xl flex items-center`} - > - - -
{name}
-

- {messages.length === 0 ? welcomeComponent : ''} - -
- {messages.length > 0 - ? [...messages].reverse().map((m, i) => { - const sourceKey = (messages.length - 1 - i).toString(); - if (m.role === 'system') { - return ( - - ); - } - if (/\$\$TOOLS\$\$/.test(m.content) && enableImgGeneration) { - if (/\$\$END\$\$/.test(m.content)) { - return ( - - ); - } - return ( - - ); - } - return ( - - ); - }) - : ''} -
- - {messages.length === 0 && ingestForm} -
-
{intemediateStepsToggle}
- -
- -