From 8e4c56ebea9e45a24ae3dcd85cfc0561289fadc6 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 17 Nov 2024 21:52:02 -0800 Subject: [PATCH] chat peeks --- core/indexing/docs/DocsService.ts | 57 +++++++-------- gui/src/components/Footer.tsx | 71 +++++++++---------- ...ndexingPeeks.tsx => ChatIndexingPeeks.tsx} | 49 +++++++++---- .../components/indexing/IndexingStatus.tsx | 9 ++- .../components/indexing/IndexingStatuses.tsx | 1 - gui/src/pages/gui/Chat.tsx | 2 + 6 files changed, 107 insertions(+), 82 deletions(-) rename gui/src/components/indexing/{FooterIndexingPeeks.tsx => ChatIndexingPeeks.tsx} (58%) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 7c163667b..cc75c3835 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -37,6 +37,12 @@ import { } from "./preIndexed"; import preIndexedDocs from "./preIndexedDocs"; +// Progress heuristic values +// subpages -> embeddings -> delete from db -> add to db +const PROGRESS_AT_EMBEDDING = 0.5; +const PROGRESS_AT_DELETE_OPERATIONS = 0.7; +const PROGRESS_AT_ADD_OPERATIONS = 0.8; + // Purposefully lowercase because lancedb converts export interface LanceDbDocsRow { title: string; @@ -140,6 +146,8 @@ export default class DocsService { this.handleStatusUpdate({ ...status, status: "aborted", + progress: 0, + description: "Canceled", }); } } @@ -148,20 +156,20 @@ export default class DocsService { return this.statuses.get(startUrl)?.status === "aborted"; } - // Pausing not supported for docs yet - // setPaused(startUrl: string, pause: boolean) { - // const status = this.statuses.get(startUrl); - // if (status) { - // this.handleStatusUpdate({ - // ...status, - // status: pause ? "paused" : "indexing", - // }); - // } - // } + // NOTE Pausing not supported for docs yet + setPaused(startUrl: string, pause: boolean) { + const status = this.statuses.get(startUrl); + if (status) { + this.handleStatusUpdate({ + ...status, + status: pause ? "paused" : "indexing", + }); + } + } - // isPaused(startUrl: string) { - // return this.statuses.get(startUrl)?.status === "paused"; - // } + isPaused(startUrl: string) { + return this.statuses.get(startUrl)?.status === "paused"; + } /* * Currently, we generate and host embeddings for pre-indexed docs using transformers. @@ -372,11 +380,11 @@ export default class DocsService { const articles: Article[] = []; let processedPages = 0; - let maxKnownPages = 1; + let estimatedProgress = 0; // progress heuristic = sum series 1/(3*2^n) from n=0 to pages. Alternative e.g. sum 1/(2^n) // Crawl pages and retrieve info as articles for await (const page of this.docsCrawler.crawl(new URL(startUrl))) { - processedPages++; + estimatedProgress += 1 / (3 * 2 ** processedPages); const article = pageToArticle(page); @@ -386,9 +394,6 @@ export default class DocsService { articles.push(article); - // Use a heuristic approach for progress calculation - const progress = Math.min(processedPages / maxKnownPages, 1); - if (this.isAborted(startUrl)) { return; } @@ -396,15 +401,11 @@ export default class DocsService { ...fixedStatus, description: `Finding subpages (${page.path})`, status: "indexing", - progress, // Yield the heuristic progress + progress: 0.4 * estimatedProgress, // 0% -> 40%, a heuristic approach for progress calculation }); - // Increase maxKnownPages to delay progress reaching 100% too soon - if (processedPages === maxKnownPages) { - maxKnownPages *= 2; - } - - await new Promise((resolve) => setTimeout(resolve, 50)); + processedPages++; + await new Promise((resolve) => setTimeout(resolve, 50)); // Locks down GUI if no sleeping } void Telemetry.capture("docs_pages_crawled", { @@ -427,7 +428,7 @@ export default class DocsService { ...fixedStatus, status: "indexing", description: `Creating Embeddings: ${article.subpath}`, - progress: i / articles.length, + progress: 0.4 + 0.4 * (i / articles.length), // 40% -> 80% }); try { @@ -484,7 +485,7 @@ export default class DocsService { ...fixedStatus, description: "Deleting old embeddings from the db", status: "indexing", - progress: 0.5, + progress: 0.8, }); // Delete indexed docs if re-indexing @@ -502,7 +503,7 @@ export default class DocsService { ...fixedStatus, description: `Adding ${embeddings.length} embeddings to db`, status: "indexing", - progress: 0.5, + progress: 0.85, }); await this.add({ diff --git a/gui/src/components/Footer.tsx b/gui/src/components/Footer.tsx index bf51abc0f..0c094155c 100644 --- a/gui/src/components/Footer.tsx +++ b/gui/src/components/Footer.tsx @@ -14,7 +14,6 @@ import { ROUTES } from "../util/navigation"; import HeaderButtonWithToolTip from "./gui/HeaderButtonWithToolTip"; import FreeTrialProgressBar from "./loaders/FreeTrialProgressBar"; import ProfileSwitcher from "./ProfileSwitcher"; -import FooterIndexingPeeks from "./indexing/FooterIndexingPeeks"; function Footer() { const navigate = useNavigate(); @@ -48,49 +47,45 @@ function Footer() { } return ( - <> - - -
-
- - {defaultModel?.provider === "free-trial" && ( - - )} -
- -
- {configError && ( - - - - )} +
+
+ + {defaultModel?.provider === "free-trial" && ( + + )} +
+
+ {configError && ( - + + )} - - - -
-
- + + + + + + + +
+
); } diff --git a/gui/src/components/indexing/FooterIndexingPeeks.tsx b/gui/src/components/indexing/ChatIndexingPeeks.tsx similarity index 58% rename from gui/src/components/indexing/FooterIndexingPeeks.tsx rename to gui/src/components/indexing/ChatIndexingPeeks.tsx index c95e8db7d..d5fffd138 100644 --- a/gui/src/components/indexing/FooterIndexingPeeks.tsx +++ b/gui/src/components/indexing/ChatIndexingPeeks.tsx @@ -2,9 +2,12 @@ import { useDispatch, useSelector } from "react-redux"; import { RootState } from "../../redux/store"; import { IndexingStatus } from "core"; -import { useContext, useMemo } from "react"; +import { useContext, useMemo, useState } from "react"; import { STATUS_TO_ICON } from "./utils"; import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { useNavigate } from "react-router-dom"; +import { XMarkIcon } from "@heroicons/react/24/outline"; +import { current } from "@reduxjs/toolkit"; interface IndexingStatusViewerProps { status: IndexingStatus; @@ -12,6 +15,7 @@ interface IndexingStatusViewerProps { function FooterIndexingPeek({ status }: IndexingStatusViewerProps) { const ideMessenger = useContext(IdeMessengerContext); + const navigate = useNavigate(); const progressPercentage = useMemo(() => { return Math.min(100, Math.max(0, status.progress * 100)); @@ -20,23 +24,33 @@ function FooterIndexingPeek({ status }: IndexingStatusViewerProps) { const Icon = STATUS_TO_ICON[status.status]; return ( -
+
{ + navigate("/more"); + }} + >
{ + onClick={(e) => { if (status.url) { ideMessenger.post("openUrl", status.url); + e.stopPropagation(); } }} > {status.icon ? ( - doc icon + icon ) : null} -

+

{status.title ?? status.id}

-
+
-
+
{progressPercentage.toFixed(0)}% {Icon ? ( ) : null}
+ {/* */}
); } -function FooterIndexingPeeks() { +function ChatIndexingPeeks() { const indexingStatuses = useSelector( (store: RootState) => store.state.indexingStatuses, ); + const [hidden, setHidden] = useState(false); const currentlyIndexingDocs = useMemo(() => { return Object.values(indexingStatuses).filter( (status) => status.status === "indexing", ); }, [indexingStatuses]); + if (!currentlyIndexingDocs.length) return null; + return ( - <> - {currentlyIndexingDocs.map((status) => { - return ; - })} - +
+

Indexing in progress

+ {hidden + ? null + : currentlyIndexingDocs.map((status) => { + return ; + })} +
); } -export default FooterIndexingPeeks; +export default ChatIndexingPeeks; diff --git a/gui/src/components/indexing/IndexingStatus.tsx b/gui/src/components/indexing/IndexingStatus.tsx index eb53fd794..bb4f1d546 100644 --- a/gui/src/components/indexing/IndexingStatus.tsx +++ b/gui/src/components/indexing/IndexingStatus.tsx @@ -9,6 +9,7 @@ import { PauseCircleIcon, XMarkIcon, } from "@heroicons/react/24/outline"; +import { updateIndexingStatus } from "../../redux/slices/stateSlice"; interface IndexingStatusViewerProps { status: IndexingStatus; @@ -27,6 +28,7 @@ const STATUS_TO_ICON: Record = { function IndexingStatusViewer({ status }: IndexingStatusViewerProps) { const ideMessenger = useContext(IdeMessengerContext); const posthog = usePostHog(); + const dispatch = useDispatch(); const reIndex = () => ideMessenger.post("indexing/reindex", { @@ -34,11 +36,16 @@ function IndexingStatusViewer({ status }: IndexingStatusViewerProps) { id: status.id, }); - const abort = () => + const abort = () => { ideMessenger.post("indexing/abort", { type: status.type, id: status.id, }); + // Optimistic abort status + dispatch( + updateIndexingStatus({ ...status, status: "aborted", progress: 0 }), + ); + }; const progressPercentage = useMemo(() => { return Math.min(100, Math.max(0, status.progress * 100)); diff --git a/gui/src/components/indexing/IndexingStatuses.tsx b/gui/src/components/indexing/IndexingStatuses.tsx index bd7a61f44..51f28ba9f 100644 --- a/gui/src/components/indexing/IndexingStatuses.tsx +++ b/gui/src/components/indexing/IndexingStatuses.tsx @@ -18,7 +18,6 @@ function IndexingStatuses() { (status) => status.type === "docs" && status.status !== "deleted", ); - return []; return docs; }, [indexingStatuses]); const dispatch = useDispatch(); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 1cb6d66d6..366834ec6 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -62,6 +62,7 @@ import { } from "../../util"; import { FREE_TRIAL_LIMIT_REQUESTS } from "../../util/freeTrial"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; +import ChatIndexingPeeks from "../../components/indexing/ChatIndexingPeeks"; const StopButton = styled.div` background-color: ${vscBackground}; @@ -505,6 +506,7 @@ export function Chat() { )}
+ ); }