This commit is contained in:
Nate Sesti 2024-07-20 10:23:47 -07:00
commit 38d98e4801
5 changed files with 60 additions and 2255 deletions

View file

@ -28,22 +28,6 @@ class DocsContextProvider extends BaseContextProvider {
this.docsService = DocsService.getInstance();
}
private async _getIconDataUrl(url: string): Promise<string | undefined> {
try {
const response = await fetch(url);
if (!response.headers.get("content-type")?.startsWith("image/")) {
console.log("Not an image: ", await response.text());
return undefined;
}
const buffer = await response.buffer();
const base64data = buffer.toString("base64");
return `data:${response.headers.get("content-type")};base64,${base64data}`;
} catch (e) {
console.log("E: ", e);
return undefined;
}
}
async getContextItems(
query: string,
extras: ContextProviderExtras,
@ -115,7 +99,9 @@ class DocsContextProvider extends BaseContextProvider {
}
// Get indexed docs as ContextSubmenuItems from database.
private async _getIndexedDocsContextSubmenuItems(): Promise<ContextSubmenuItem[]> {
private async _getIndexedDocsContextSubmenuItems(): Promise<
ContextSubmenuItem[]
> {
return (await this.docsService.list()).map((doc) => ({
title: doc.title,
description: new URL(doc.baseUrl).hostname,
@ -137,7 +123,9 @@ class DocsContextProvider extends BaseContextProvider {
id: config.startUrl,
title: config.title,
description: new URL(config.startUrl).hostname,
metadata: { preIndexed: !!configs.find((cnf) => cnf.title === config.title), },
metadata: {
preIndexed: !!configs.find((cnf) => cnf.title === config.title),
},
});
}
@ -159,15 +147,6 @@ class DocsContextProvider extends BaseContextProvider {
}
});
// const icons = await Promise.all(
// submenuItems.map(async (item) =>
// item.iconUrl ? this._getIconDataUrl(item.iconUrl) : undefined,
// ),
// );
// icons.forEach((icon, i) => {
// submenuItems[i].iconUrl = icon;
// });
return submenuItems;
}
}

View file

@ -56,11 +56,5 @@ const Providers: (typeof BaseContextProvider)[] = [
export function contextProviderClassFromName(
name: ContextProviderName,
): typeof BaseContextProvider | undefined {
const cls = Providers.find((cls) => cls.description.title === name);
if (!cls) {
return undefined;
}
return cls;
return Providers.find((cls) => cls.description.title === name);
}

View file

@ -16,7 +16,7 @@ const IGNORE_PATHS_ENDING_IN = [
"changelog.html",
];
const GITHUB_PATHS_TO_TRAVERSE = ["/blob/", "/tree/"];
const markdownRegex = new RegExp(/\.(md|mdx)$/);
async function getDefaultBranch(owner: string, repo: string): Promise<string> {
const octokit = new Octokit({ auth: undefined });
@ -53,7 +53,10 @@ async function crawlGithubRepo(baseUrl: URL) {
);
const paths = tree.data.tree
.filter((file: any) => file.type === "blob" && file.path?.endsWith(".md"))
.filter(
(file: any) =>
file.type === "blob" && markdownRegex.test(file.path ?? ""),
)
.map((file: any) => baseUrl.pathname + "/tree/main/" + file.path);
return paths;

View file

@ -1395,6 +1395,46 @@
}
},
"allOf": [
{
"if": {
"properties": {
"name": {
"enum": ["docs"]
}
}
},
"then": {
"properties": {
"params": {
"properties": {
"sites": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"startUrl": {
"type": "string"
},
"rootUrl": {
"type": "string"
},
"maxDepth": {
"type": "integer"
}
},
"required": ["title", "startUrl"]
}
}
},
"required": ["sites"]
}
},
"required": ["params"]
}
},
{
"if": {
"properties": {
@ -1955,7 +1995,13 @@
"type": "object",
"properties": {
"name": {
"enum": ["cohere", "voyage", "llm", "free-trial", "huggingface-tei"]
"enum": [
"cohere",
"voyage",
"llm",
"free-trial",
"huggingface-tei"
]
},
"params": {
"type": "object"
@ -2070,7 +2116,7 @@
"default": false
},
"truncation_direction": {
"enum": ["Right","Left"],
"enum": ["Right", "Left"],
"markdownDescription": "Wether to truncate sequences from the `left` or `right`.",
"default": "Right"
}

File diff suppressed because it is too large Load diff