chat peeks

This commit is contained in:
Dallin Romney 2024-11-17 21:52:02 -08:00
parent f52fbca1d5
commit 8e4c56ebea
6 changed files with 107 additions and 82 deletions

View file

@ -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({

View file

@ -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 (
<>
<FooterIndexingPeeks />
<footer className="flex h-7 items-center justify-between overflow-hidden border-0 border-t border-solid border-t-zinc-700 p-2">
<div className="flex max-w-[40vw] gap-2">
<ProfileSwitcher />
{defaultModel?.provider === "free-trial" && (
<FreeTrialProgressBar
completed={parseInt(localStorage.getItem("ftc") || "0")}
total={FREE_TRIAL_LIMIT_REQUESTS}
/>
)}
</div>
<div className="flex gap-1">
{configError && (
<HeaderButtonWithToolTip
tooltipPlacement="top-end"
text="Config error"
onClick={onClickError}
>
<ExclamationTriangleIcon className="h-4 w-4" />
</HeaderButtonWithToolTip>
)}
<footer className="flex h-7 items-center justify-between overflow-hidden border-0 border-t border-solid border-t-zinc-700 p-2">
<div className="flex max-w-[40vw] gap-2">
<ProfileSwitcher />
{defaultModel?.provider === "free-trial" && (
<FreeTrialProgressBar
completed={parseInt(localStorage.getItem("ftc") || "0")}
total={FREE_TRIAL_LIMIT_REQUESTS}
/>
)}
</div>
<div className="flex gap-1">
{configError && (
<HeaderButtonWithToolTip
tooltipPlacement="top-end"
text="More"
onClick={onClickMore}
text="Config error"
onClick={onClickError}
>
<EllipsisHorizontalCircleIcon className="h-4 w-4" />
<ExclamationTriangleIcon className="h-4 w-4" />
</HeaderButtonWithToolTip>
)}
<HeaderButtonWithToolTip
tooltipPlacement="top-end"
onClick={onClickSettings}
text="Configure Continue"
>
<Cog6ToothIcon className="h-4 w-4" />
</HeaderButtonWithToolTip>
</div>
</footer>
</>
<HeaderButtonWithToolTip
tooltipPlacement="top-end"
text="More"
onClick={onClickMore}
>
<EllipsisHorizontalCircleIcon className="h-4 w-4" />
</HeaderButtonWithToolTip>
<HeaderButtonWithToolTip
tooltipPlacement="top-end"
onClick={onClickSettings}
text="Configure Continue"
>
<Cog6ToothIcon className="h-4 w-4" />
</HeaderButtonWithToolTip>
</div>
</footer>
);
}

View file

@ -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 (
<div className="border-t-1 flex flex-row items-center gap-2 border border-0 border-gray-400 px-2 py-1">
<div
className="flex cursor-pointer flex-row items-center gap-2 hover:opacity-60"
onClick={() => {
navigate("/more");
}}
>
<div
className={`flex flex-row items-center gap-2 ${status.url ? "hover:cursor-pointer hover:underline" : ""}`}
onClick={() => {
onClick={(e) => {
if (status.url) {
ideMessenger.post("openUrl", status.url);
e.stopPropagation();
}
}}
>
{status.icon ? (
<img src={status.icon} alt="doc icon" className="h-4 w-4" />
<img
src={status.icon}
alt="icon"
className="2xs:block hidden h-4 w-4"
/>
) : null}
<p className="lines lines-1 m-0 p-0 text-left">
<p className="lines lines-1 m-0 max-w-20 p-0 text-left">
{status.title ?? status.id}
</p>
</div>
<div className="my-2 h-1.5 w-full rounded-md border border-solid border-gray-400">
<div className="my-2 h-1.5 flex-1 rounded-md border border-solid border-gray-400">
<div
className={`h-full rounded-lg bg-stone-500 transition-all duration-200 ease-in-out`}
style={{
@ -44,7 +58,7 @@ function FooterIndexingPeek({ status }: IndexingStatusViewerProps) {
}}
/>
</div>
<div className="flex flex-row items-center gap-1 text-stone-500">
<div className="xs:flex hidden flex-row items-center gap-1 text-stone-500">
<span className="text-xs">{progressPercentage.toFixed(0)}%</span>
{Icon ? (
<Icon
@ -54,27 +68,34 @@ function FooterIndexingPeek({ status }: IndexingStatusViewerProps) {
></Icon>
) : null}
</div>
{/* <XMarkIcon className="h-4 w-4 text-stone-500" /> */}
</div>
);
}
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 <FooterIndexingPeek status={status} />;
})}
</>
<div className="flex flex-col gap-1 px-2 py-1">
<p className="m-0 p-0">Indexing in progress</p>
{hidden
? null
: currentlyIndexingDocs.map((status) => {
return <FooterIndexingPeek status={status} />;
})}
</div>
);
}
export default FooterIndexingPeeks;
export default ChatIndexingPeeks;

View file

@ -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<IndexingStatus["status"], any> = {
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));

View file

@ -18,7 +18,6 @@ function IndexingStatuses() {
(status) => status.type === "docs" && status.status !== "deleted",
);
return [];
return docs;
}, [indexingStatuses]);
const dispatch = useDispatch();

View file

@ -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() {
)}
</div>
</div>
<ChatIndexingPeeks />
</>
);
}