mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-27 21:21:03 +00:00
feat: prettier and eslint
This commit is contained in:
@@ -2,15 +2,21 @@ import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
export default function addTrainData(eventData) {
|
||||
const file = readFileSync(join(global.__dirname, global.config.fasttext.trainFile), 'utf-8');
|
||||
const data = file.split('\n');
|
||||
const { label, text } = eventData;
|
||||
const file = readFileSync(
|
||||
join(global.__dirname, global.config.fasttext.trainFile),
|
||||
'utf-8'
|
||||
);
|
||||
const data = file.split('\n');
|
||||
const { label, text } = eventData;
|
||||
|
||||
const labelIndex = data.findIndex((data) => data.startsWith(label));
|
||||
const labelIndex = data.findIndex((data) => data.startsWith(label));
|
||||
|
||||
data.splice(labelIndex === -1 ? 0 : labelIndex, 0, `${label} ${text}`);
|
||||
data.splice(labelIndex === -1 ? 0 : labelIndex, 0, `${label} ${text}`);
|
||||
|
||||
writeFileSync(join(global.__dirname, global.config.fasttext.trainFile), data.join('\n'));
|
||||
writeFileSync(
|
||||
join(global.__dirname, global.config.fasttext.trainFile),
|
||||
data.join('\n')
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { serialize } from 'bson';
|
||||
|
||||
export default async function runAI(client, data) {
|
||||
const predictions = await global.ft.predict(data.text);
|
||||
const jsonData = {
|
||||
op: 2,
|
||||
id: data.id,
|
||||
predictions
|
||||
};
|
||||
const predictions = await global.ft.predict(data.text);
|
||||
const jsonData = {
|
||||
op: 2,
|
||||
id: data.id,
|
||||
predictions
|
||||
};
|
||||
|
||||
const bsonData = serialize(jsonData);
|
||||
client.write(bsonData);
|
||||
|
||||
return;
|
||||
}
|
||||
const bsonData = serialize(jsonData);
|
||||
client.write(bsonData);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,4 @@ import trainAI from './trainAI.js';
|
||||
import runOCR from './ocr.js';
|
||||
import addTrainData from './addTrainData.js';
|
||||
|
||||
export {
|
||||
runAI,
|
||||
trainAI,
|
||||
runOCR,
|
||||
addTrainData
|
||||
}
|
||||
export { runAI, trainAI, runOCR, addTrainData };
|
||||
|
||||
@@ -2,22 +2,22 @@ import { recognize } from 'node-tesseract-ocr';
|
||||
import { serialize } from 'bson';
|
||||
|
||||
export default async function runOCR(client, eventData) {
|
||||
const config = {
|
||||
lang: 'eng',
|
||||
oem: 3,
|
||||
psm: 3,
|
||||
};
|
||||
const config = {
|
||||
lang: 'eng',
|
||||
oem: 3,
|
||||
psm: 3
|
||||
};
|
||||
|
||||
const ocrText = await recognize(eventData.url, config);
|
||||
const ocrText = await recognize(eventData.url, config);
|
||||
|
||||
const jsonData = {
|
||||
op: 6,
|
||||
id: eventData.id,
|
||||
ocrText
|
||||
};
|
||||
const jsonData = {
|
||||
op: 6,
|
||||
id: eventData.id,
|
||||
ocrText
|
||||
};
|
||||
|
||||
const bsonData = serialize(jsonData);
|
||||
client.write(bsonData);
|
||||
const bsonData = serialize(jsonData);
|
||||
client.write(bsonData);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,53 +2,56 @@ import FastText from 'fasttext.js';
|
||||
import { join } from 'node:path';
|
||||
|
||||
export default async function trainAI() {
|
||||
const ft = new FastText({
|
||||
train: {
|
||||
// number of concurrent threads
|
||||
thread: 8,
|
||||
// verbosity level [2]
|
||||
verbose: 4,
|
||||
// number of negatives sampled [5]
|
||||
neg: 7,
|
||||
// loss function {ns, hs, softmax} [ns]
|
||||
loss: 'ns',
|
||||
// learning rate [0.05]
|
||||
lr: 1,
|
||||
// change the rate of updates for the learning rate [100]
|
||||
lrUpdateRate: 1000,
|
||||
// max length of word ngram [1]
|
||||
wordNgrams: 5,
|
||||
// minimal number of word occurences
|
||||
minCount: 1,
|
||||
// minimal number of word occurences
|
||||
minCountLabel: 1,
|
||||
// size of word vectors [100]
|
||||
dim: 100,
|
||||
// size of the context window [5]
|
||||
ws: 5,
|
||||
// number of epochs [5]
|
||||
epoch: 20,
|
||||
// number of buckets [2000000]
|
||||
bucket: 2000000,
|
||||
// min length of char ngram [3]
|
||||
minn: process.env.TRAIN_MINN || 3,
|
||||
// max length of char ngram [6]
|
||||
maxn: process.env.TRAIN_MAXN || 6,
|
||||
// sampling threshold [0.0001]
|
||||
t: 0.0001,
|
||||
// load pre trained word vectors from unsupervised model
|
||||
pretrainedVectors: ''
|
||||
},
|
||||
serializeTo: join(global.__dirname, global.config.fasttext.loadModel).replace('.bin', ''),
|
||||
trainFile: join(global.__dirname, global.config.fasttext.trainFile),
|
||||
bin: join(global.__dirname, global.config.fasttext.bin)
|
||||
});
|
||||
|
||||
global.ft.unload();
|
||||
const ft = new FastText({
|
||||
train: {
|
||||
// number of concurrent threads
|
||||
thread: 8,
|
||||
// verbosity level [2]
|
||||
verbose: 4,
|
||||
// number of negatives sampled [5]
|
||||
neg: 7,
|
||||
// loss function {ns, hs, softmax} [ns]
|
||||
loss: 'ns',
|
||||
// learning rate [0.05]
|
||||
lr: 1,
|
||||
// change the rate of updates for the learning rate [100]
|
||||
lrUpdateRate: 1000,
|
||||
// max length of word ngram [1]
|
||||
wordNgrams: 5,
|
||||
// minimal number of word occurences
|
||||
minCount: 1,
|
||||
// minimal number of word occurences
|
||||
minCountLabel: 1,
|
||||
// size of word vectors [100]
|
||||
dim: 100,
|
||||
// size of the context window [5]
|
||||
ws: 5,
|
||||
// number of epochs [5]
|
||||
epoch: 20,
|
||||
// number of buckets [2000000]
|
||||
bucket: 2000000,
|
||||
// min length of char ngram [3]
|
||||
minn: process.env.TRAIN_MINN || 3,
|
||||
// max length of char ngram [6]
|
||||
maxn: process.env.TRAIN_MAXN || 6,
|
||||
// sampling threshold [0.0001]
|
||||
t: 0.0001,
|
||||
// load pre trained word vectors from unsupervised model
|
||||
pretrainedVectors: ''
|
||||
},
|
||||
serializeTo: join(
|
||||
global.__dirname,
|
||||
global.config.fasttext.loadModel
|
||||
).replace('.bin', ''),
|
||||
trainFile: join(global.__dirname, global.config.fasttext.trainFile),
|
||||
bin: join(global.__dirname, global.config.fasttext.bin)
|
||||
});
|
||||
|
||||
await ft.train()
|
||||
global.ft.unload();
|
||||
|
||||
global.ft.load();
|
||||
await ft.train();
|
||||
|
||||
return;
|
||||
}
|
||||
global.ft.load();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user