Load NLP transformer from models/transformers folder to prevent big docker image
This commit is contained in:
parent
29f2c0d869
commit
7b7852e46e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
.env
|
||||
node_modules/
|
||||
src/models/transformers/*
|
||||
@ -2,5 +2,6 @@ module.exports = {
|
||||
FORCE_DB_SYNC: process.env.FORCE_DB_SYNC,
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
PORT: process.env.PORT,
|
||||
DEVICE_ID: process.env.DEVICE_ID
|
||||
DEVICE_ID: process.env.DEVICE_ID,
|
||||
NLP_TRANSFORMER: process.env.NLP_TRANSFORMER
|
||||
};
|
||||
|
||||
@ -3,7 +3,10 @@ if (process.env.NODE_ENV !== "production") {
|
||||
require("dotenv").config();
|
||||
}
|
||||
|
||||
const {pipeline} = require("@xenova/transformers");
|
||||
const {env, pipeline} = require("@xenova/transformers");
|
||||
const path = require("path");
|
||||
env.allowRemoteModels = false;
|
||||
env.localModelPath = path.resolve(__dirname, "./models/transformers").replace(/\\/g, "/");
|
||||
|
||||
const models = require("./models");
|
||||
const db = models.db;
|
||||
@ -65,7 +68,10 @@ function cosineSimilarity(a, b) {
|
||||
}
|
||||
|
||||
async function initModel() {
|
||||
extractor = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
|
||||
extractor = await pipeline("feature-extraction", `${config.NLP_TRANSFORMER}`, {
|
||||
dtype: 'fp32',
|
||||
quantized: false
|
||||
});
|
||||
console.log("MiniLM model loaded");
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user