Skip to content

Commit

Permalink
Replace cheerio with node-html-parser to minimize size (#125)
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon authored Nov 4, 2024
1 parent 8c3de83 commit 545571b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 159 deletions.
Binary file modified media/installmodels.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/installollama.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 10 additions & 149 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
},
"dependencies": {
"@redhat-developer/vscode-redhat-telemetry": "^0.9.0",
"cheerio": "^1.0.0"
"node-html-parser": "^6.1.13"
}
}
}
16 changes: 8 additions & 8 deletions src/ollama/ollamaLibrary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as cheerio from 'cheerio';
import { parse } from 'node-html-parser';
import { ModelInfo } from '../commons/modelInfo';

const cache = new Map<string, ModelInfo | undefined>();//TODO limit caching lifespan
Expand All @@ -22,19 +22,19 @@ export async function getRemoteModelInfo(modelId: string): Promise<ModelInfo | u
}

const html = await response.text();
const $ = cheerio.load(html);
const fileExplorer = $('#file-explorer');
const itemsCenter = fileExplorer.find('.items-center');
const lastParagraphElement = itemsCenter.find('p').last();
const root = parse(html);
const fileExplorer = root.querySelector('#file-explorer');
const itemsCenter = fileExplorer?.querySelector('.items-center');
const lastParagraphElement = itemsCenter?.querySelectorAll('p')?.pop();

if (lastParagraphElement.length > 0) {
const lastParagraph = lastParagraphElement.text().trim();
if (lastParagraphElement) {
const lastParagraph = lastParagraphElement.text.trim();
if (lastParagraph.includes(INFO_DELIMITER)) {
const [digest, size] = lastParagraph.split(INFO_DELIMITER).map(item => item.trim());
const data: ModelInfo = {
id: modelId,
size,
digest
digest: "x" + digest
};
// Cache the successful result
cache.set(modelId, data);
Expand Down

0 comments on commit 545571b

Please sign in to comment.