From c93f7436abd60314d3bb67ab371472b665d4ed9a Mon Sep 17 00:00:00 2001 From: bracesproul Date: Thu, 17 Oct 2024 09:43:16 -0700 Subject: [PATCH] cr --- frontend/app/components/DocumentCard.tsx | 28 ++++ .../components/GeneratingQuestionsToolUI.tsx | 122 ++++++++++++------ .../components/SelectedDocumentsToolUI.tsx | 29 +---- 3 files changed, 112 insertions(+), 67 deletions(-) create mode 100644 frontend/app/components/DocumentCard.tsx diff --git a/frontend/app/components/DocumentCard.tsx b/frontend/app/components/DocumentCard.tsx new file mode 100644 index 00000000..1fa50828 --- /dev/null +++ b/frontend/app/components/DocumentCard.tsx @@ -0,0 +1,28 @@ +import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"; + +export type Document = { + page_content: string; + metadata: Record; +}; + +export const DocumentCard = ({ document }: { document: Document }) => { + const description = + document.metadata.description && document.metadata.description !== "" + ? document.metadata.description + : document.page_content.slice(0, 250); + + return ( + + + + {document.metadata.title} + + + +

+ {description} +

+
+
+ ); +}; diff --git a/frontend/app/components/GeneratingQuestionsToolUI.tsx b/frontend/app/components/GeneratingQuestionsToolUI.tsx index aff73dec..af780b1e 100644 --- a/frontend/app/components/GeneratingQuestionsToolUI.tsx +++ b/frontend/app/components/GeneratingQuestionsToolUI.tsx @@ -1,6 +1,6 @@ import { useAssistantToolUI } from "@assistant-ui/react"; import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"; -import { LoaderCircle, Globe } from "lucide-react"; +import { LoaderCircle, Globe, Plus } from "lucide-react"; import { DocumentDialog } from "./DocumentDialog"; import { Tooltip, @@ -8,53 +8,97 @@ import { TooltipProvider, TooltipTrigger, } from "./ui/tooltip"; +import { Sheet, SheetContent, SheetTrigger } from "./ui/sheet"; +import { TooltipIconButton } from "./ui/assistant-ui/tooltip-icon-button"; +import { DocumentCard, Document } from "./DocumentCard"; type Question = { question: string; step: number; // Not rendered in the UI ATM. queries?: string[]; - documents?: Record[]; + documents?: Document[]; }; -const QuestionCard = ({ question }: { question: Question }) => ( - - - - - - - {question.question} - - - -

{question.question}

-
-
-
-
- -
-
-
- {question.documents?.length ? ( - question.documents?.map((doc: Record, idx: number) => ( - - )) - ) : ( - -

Finding documents

- -
- )} +const QuestionCard = ({ question }: { question: Question }) => { + const displayedDocuments = question.documents?.slice(0, 6) || []; + const remainingDocuments = question.documents?.slice(6) || []; + + return ( + + + + + + + {question.question} + + + +

{question.question}

+
+
+
+
+ +
+
+
+ {question.documents?.length ? ( + <> + {displayedDocuments.map((doc: Document, idx: number) => ( + + ))} + {remainingDocuments.length > 0 && ( + + + + + + + +
+

+ All Documents for Question +

+
+ {question.documents?.map( + (doc: Document, idx: number) => ( + } + /> + ), + )} +
+
+
+
+ )} + + ) : ( + +

Finding documents

+ +
+ )} +
-
- - -); + + + ); +}; export const useGeneratingQuestionsUI = () => useAssistantToolUI({ diff --git a/frontend/app/components/SelectedDocumentsToolUI.tsx b/frontend/app/components/SelectedDocumentsToolUI.tsx index 5915d203..b9154075 100644 --- a/frontend/app/components/SelectedDocumentsToolUI.tsx +++ b/frontend/app/components/SelectedDocumentsToolUI.tsx @@ -1,35 +1,8 @@ import { useAssistantToolUI } from "@assistant-ui/react"; -import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"; import { BookOpenText, Plus } from "lucide-react"; import { Sheet, SheetContent, SheetTrigger } from "./ui/sheet"; import { DocumentDialog } from "./DocumentDialog"; - -type Document = { - page_content: string; - metadata: Record; -}; - -const DocumentCard = ({ document }: { document: Document }) => { - const description = - document.metadata.description && document.metadata.description !== "" - ? document.metadata.description - : document.page_content.slice(0, 250); - - return ( - - - - {document.metadata.title} - - - -

- {description} -

-
-
- ); -}; +import { DocumentCard, Document } from "./DocumentCard"; export const useSelectedDocumentsUI = () => useAssistantToolUI({