tzmtwtr commited on
Commit
fc3fe88
1 Parent(s): fbe0334

ready to use as npm package

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. index.js +25 -0
  3. package.json +7 -0
  4. tsconfig.json +10 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ node_modules
index.js ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.embedding_calc = void 0;
13
+ const transformers_1 = require("@xenova/transformers");
14
+ transformers_1.env.localModelPath = 'node_modules/embedding/model';
15
+ let pipe = null;
16
+ const piping = (0, transformers_1.pipeline)("feature-extraction", "sentence-transformers/paraphrase-multilingual-mpnet-base-v2", { local_files_only: true, quantized: true }).then(p => { pipe = p; });
17
+ function embedding_calc(text) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ yield piping;
20
+ if (pipe) {
21
+ return yield pipe(text);
22
+ }
23
+ });
24
+ }
25
+ exports.embedding_calc = embedding_calc;
package.json CHANGED
@@ -2,6 +2,13 @@
2
  "name": "embedding",
3
  "version": "0.1.0",
4
  "private": false,
 
 
 
 
 
 
 
5
  "dependencies": {
6
  "@xenova/transformers": "^2.8.0"
7
  },
 
2
  "name": "embedding",
3
  "version": "0.1.0",
4
  "private": false,
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepare": "npm run build",
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
  "dependencies": {
13
  "@xenova/transformers": "^2.8.0"
14
  },
tsconfig.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
4
+ "module": "commonjs", /* Specify what module code is generated. */
5
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
6
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
7
+ "strict": true, /* Enable all strict type-checking options. */
8
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
9
+ }
10
+ }