huggingface / huggingface/transformers.js

[Question] Using transformers.js inside an Obsidian Plugin

Open
#291 11 comments 2 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
16.3k
Forks
1.2k
Avg merge
6d 2h
Merged PRs (30d)
6

Description

I'm trying to run transfomer.js inside of Obsidian but running into some errors:
Screenshot 2023-09-10 at 3 05 43 PM

This code is triggering the issues:
```js

class MyClassificationPipeline {
static task = "text-classification";
static model = "Xenova/distilbert-base-uncased-finetuned-sst-2-english";
static instance = null;

static async getInstance(progress_callback = null) {
if (this.instance === null) {
// Dynamically import the Transformers.js library
console.log('before import')
let { pipeline, env } = await import("@xenova/transformers");
console.log('after import')

// NOTE: Uncomment this to change the cache directory
// env.cacheDir = './.cache';

this.instance = pipeline(this.task, this.model, {
progress_callback,
});
}

return this.instance;
}
}
export default MyClassificationPipeline;

// Comment out this line if you don't want to start loading the model as soon as the server starts.
// If commented out, the model will be loaded when the first request is received (i.e,. lazily).
// MyClassificationPipeline.getInstance();
```
[Link to source](https://github.com/different-ai/obsidian-ml/blob/master/embeddings.js)

[These are the lines that are calling the code above](https://github.com/different-ai/obsidian-ml/blob/0bd169c6e0c3f385e7238a78c585932fe0320bc9/hello.js#L27-L29)

Context about Obsidian plugins:
- Obsidian plugin is just a single imported js file.
- Most of the time it's bundled using esbuild.

In my case, this is [my esbuild setup](https://github.com/different-ai/obsidian-ml/blob/master/esbuild.config.mjs)

----

How should I be tackling this, what would be the recommended way to bundle transformer.js?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.