Skip to content

Commit

Permalink
Implement modelsInfo in browser package
Browse files Browse the repository at this point in the history
  • Loading branch information
synw committed Sep 11, 2024
1 parent 8afcbde commit 202ad37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@locallm/browser",
"version": "0.0.5",
"version": "0.0.7",
"description": "Run language models in the browser",
"repository": "https://github.com/synw/locallm",
"scripts": {
Expand Down
28 changes: 22 additions & 6 deletions packages/browser/src/wllama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,28 @@ class WllamaProvider implements LmProvider {
}

/**
* Not implemented for this provider
*
* @returns {Promise<void>}
*/
* Set the available models from the browser cache
*
* @returns {Promise<void>}
*/
async modelsInfo(): Promise<void> {
console.warn("Not implemented for this provider")
const cachedFiles = (await wllama.cacheManager.list()).filter((m) => {
return m.size === m.metadata.originalSize;
});
const cachedURLs = new Set(cachedFiles.map((e) => e.metadata.originalURL));
const models = new Set<ModelConf>();
cachedURLs.forEach((u) => {
const name = u
.split('/')
.pop()
?.replace(/-\d{5}-of-\d{5}/, '')
.replace('.gguf', '') ?? '(unknown)';
models.add({
name: name,
ctx: -1
})
})
this.models = Array.from(models);
}

async info(): Promise<Record<string, any>> {
Expand All @@ -63,7 +79,7 @@ class WllamaProvider implements LmProvider {
return wllama.getModelMetadata()
}

async loadModel(name: string, ctx?: number, threads?: number, gpu_layers?: number): Promise<void> {
async loadModel(name: string, ctx?: number): Promise<void> {
throw new Error("Not implemented for this provider: use loadBrowserModel");
}

Expand Down

0 comments on commit 202ad37

Please sign in to comment.