Fixes for dialog, remove logging, indexing corrections
This commit is contained in:
parent
78ef735634
commit
e0ecd3a8a7
6 changed files with 25 additions and 24 deletions
|
|
@ -128,6 +128,7 @@ export class Core {
|
|||
|
||||
// Context providers
|
||||
on("context/addDocs", async (msg) => {
|
||||
console.log("maxDepth: ", msg.data.maxDepth)
|
||||
for await (const _ of indexDocs(
|
||||
msg.data,
|
||||
new TransformersJsEmbeddingsProvider(),
|
||||
|
|
|
|||
|
|
@ -55,8 +55,6 @@ async function getLinksFromUrl(url: string, path: string) {
|
|||
const location = new URL(path, url);
|
||||
let response;
|
||||
|
||||
//ToDo: Should have some method of checking if location is valid or not
|
||||
|
||||
try {
|
||||
response = await fetch(location.toString());
|
||||
} catch (error: unknown) {
|
||||
|
|
@ -133,7 +131,7 @@ export type PageData = {
|
|||
};
|
||||
|
||||
export async function* crawlPage(url: URL, maxDepth: number = 3): AsyncGenerator<PageData> {
|
||||
console.log("starting crawl")
|
||||
console.log("Starting crawl from: ", url, " - Max Depth: ", maxDepth)
|
||||
const { baseUrl, basePath } = splitUrl(url);
|
||||
let paths: { path: string; depth: number }[] = [{ path: basePath, depth: 0 }];
|
||||
|
||||
|
|
@ -146,10 +144,8 @@ export async function* crawlPage(url: URL, maxDepth: number = 3): AsyncGenerator
|
|||
const promises = batch.map(({ path, depth }) => getLinksFromUrl(baseUrl, path).then(links => ({ links, path, depth }))); // Adjust for depth tracking
|
||||
|
||||
const results = await Promise.all(promises);
|
||||
console.log("results length: ", results.length)
|
||||
for (const { links: { html, links: linksArray }, path, depth } of results) {
|
||||
if (html !== "" && depth <= maxDepth) { // Check depth
|
||||
console.log("Depth: ", depth)
|
||||
yield {
|
||||
url: url.toString(),
|
||||
path,
|
||||
|
|
@ -159,7 +155,6 @@ export async function* crawlPage(url: URL, maxDepth: number = 3): AsyncGenerator
|
|||
|
||||
// Ensure we only add links if within depth limit
|
||||
if (depth < maxDepth) {
|
||||
console.log("Depth: ", depth)
|
||||
for (let link of linksArray) {
|
||||
if (!paths.some(p => p.path === link)) {
|
||||
paths.push({ path: link, depth: depth + 1 }); // Increment depth for new paths
|
||||
|
|
@ -168,10 +163,14 @@ export async function* crawlPage(url: URL, maxDepth: number = 3): AsyncGenerator
|
|||
}
|
||||
}
|
||||
} catch(e){
|
||||
console.warn("Error while crawling page: ", e)
|
||||
if (e instanceof TypeError) {
|
||||
console.warn("Error while crawling page: ", e) // likely an invalid url, continue with process
|
||||
} else {
|
||||
console.error("Error while crawling page: ", e)
|
||||
}
|
||||
}
|
||||
|
||||
index += batch.length; // Proceed to next batch
|
||||
}
|
||||
console.log("crawl completed")
|
||||
console.log("Crawl completed")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ export async function* indexDocs(
|
|||
siteIndexingConfig: SiteIndexingConfig,
|
||||
embeddingsProvider: EmbeddingsProvider,
|
||||
): AsyncGenerator<IndexingProgressUpdate> {
|
||||
console.log("In core indexDocs. maxDepth -> ", siteIndexingConfig.maxDepth, " Base Url -> ", siteIndexingConfig.startUrl)
|
||||
const startUrl = new URL(siteIndexingConfig.startUrl)
|
||||
|
||||
if (await hasDoc(siteIndexingConfig.startUrl.toString())) {
|
||||
|
|
@ -29,13 +28,10 @@ export async function* indexDocs(
|
|||
|
||||
const articles: Article[] = [];
|
||||
|
||||
console.log("starting crawl loop")
|
||||
// Crawl pages and retrieve info as articles
|
||||
for await (const page of crawlPage(startUrl, siteIndexingConfig.maxDepth)) {
|
||||
const article = pageToArticle(page);
|
||||
if (!article) { continue; }
|
||||
|
||||
console.log("pushing article")
|
||||
articles.push(article);
|
||||
|
||||
yield {
|
||||
|
|
@ -48,10 +44,10 @@ export async function* indexDocs(
|
|||
const chunks: Chunk[] = [];
|
||||
const embeddings: number[][] = [];
|
||||
|
||||
console.log("starting index of articles")
|
||||
|
||||
// Create embeddings of retrieved articles
|
||||
console.log("Creating Embeddings for ", articles.length, " articles")
|
||||
for (const article of articles) {
|
||||
// Todo: Should have some way of checking if an article is valid
|
||||
|
||||
yield {
|
||||
progress: Math.max(1, Math.floor(100 / (articles.length + 1))),
|
||||
|
|
@ -75,8 +71,8 @@ export async function* indexDocs(
|
|||
}
|
||||
}
|
||||
|
||||
console.log("adding docs")
|
||||
// Add docs to databases
|
||||
console.log("Adding ", embeddings.length, " embeddings to db")
|
||||
await addDocs(siteIndexingConfig.title, startUrl, chunks, embeddings);
|
||||
|
||||
yield {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,6 @@ export type WebviewProtocol = Protocol &
|
|||
errorPopup: [{ message: string }, void];
|
||||
"index/setPaused": [boolean, void];
|
||||
"index/forceReIndex": [undefined, void];
|
||||
"context/addDocs": [SiteIndexingConfig, void];
|
||||
openUrl: [string, void];
|
||||
applyToCurrentFile: [{ text: string }, void];
|
||||
showTutorial: [undefined, void];
|
||||
|
|
|
|||
|
|
@ -583,6 +583,7 @@ export async function showTutorial() {
|
|||
}
|
||||
});
|
||||
this.on("context/addDocs", (msg) => {
|
||||
console.log("maxDepth: ", msg.data.maxDepth)
|
||||
const siteIndexingConfig: SiteIndexingConfig = {
|
||||
startUrl: msg.data.startUrl,
|
||||
rootUrl: msg.data.rootUrl,
|
||||
|
|
@ -591,7 +592,6 @@ export async function showTutorial() {
|
|||
};
|
||||
|
||||
const embeddingsProvider = new TransformersJsEmbeddingsProvider();
|
||||
console.log("In vscode addDocs. maxDepth", siteIndexingConfig.maxDepth, " startUrl: ", siteIndexingConfig.startUrl)
|
||||
vscode.window.withProgress(
|
||||
{
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ const GridDiv = styled.div`
|
|||
`;
|
||||
|
||||
function AddDocsDialog() {
|
||||
const defaultMaxDepth = 4
|
||||
const defaultMaxDepth = 3
|
||||
const [docsUrl, setDocsUrl] = React.useState("");
|
||||
const [docsTitle, setDocsTitle] = React.useState("");
|
||||
const [urlValid, setUrlValid] = React.useState(false);
|
||||
const [maxDepth, setMaxDepth] = React.useState(defaultMaxDepth);
|
||||
const [maxDepth, setMaxDepth] = React.useState<number | string>(""); // Change here
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
|
|
@ -66,10 +66,17 @@ function AddDocsDialog() {
|
|||
/>
|
||||
<Input
|
||||
type="text"
|
||||
placeholder={`Max Depth (Default=${defaultMaxDepth})`}
|
||||
placeholder={`Optional: Max Depth (Default: ${defaultMaxDepth})`}
|
||||
title="The maximum search tree depth - where your input url is the root node"
|
||||
value={maxDepth}
|
||||
onChange={(e) => {
|
||||
setMaxDepth(Number(e.target.value))
|
||||
const value = e.target.value;
|
||||
if (value == '') {
|
||||
setMaxDepth("")
|
||||
} else if (!isNaN(+value) && Number(value) > 0) {
|
||||
setMaxDepth(Number(value))
|
||||
}
|
||||
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
|
|
@ -80,13 +87,12 @@ function AddDocsDialog() {
|
|||
startUrl: docsUrl,
|
||||
rootUrl: docsUrl,
|
||||
title: docsTitle,
|
||||
maxDepth: maxDepth
|
||||
maxDepth: typeof maxDepth === 'string' ? defaultMaxDepth : maxDepth, // Ensure maxDepth is a number
|
||||
};
|
||||
console.log("triggering addDocs. maxDepth: ", maxDepth, " docsUrl: ", docsUrl, " title: ", docsTitle)
|
||||
postToIde("context/addDocs", siteIndexingConfig);
|
||||
setDocsTitle("");
|
||||
setDocsUrl("");
|
||||
setMaxDepth(defaultMaxDepth)
|
||||
setMaxDepth("")
|
||||
dispatch(setShowDialog(false));
|
||||
addItem("docs", {
|
||||
id: docsUrl,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue