mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-14 18:35:21 +01:00
6ad786f348
x5 speed boost!!
18 lines
523 B
JavaScript
18 lines
523 B
JavaScript
const TASK = 'feature-extraction';
|
|
|
|
/**
|
|
* @param {string} text - The text to vectorize
|
|
* @returns {Promise<number[]>} - The vectorized text in form of an array of numbers
|
|
*/
|
|
async function getTransformersVector(text) {
|
|
const module = await import('./transformers.mjs');
|
|
const pipe = await module.default.getPipeline(TASK);
|
|
const result = await pipe(text, { pooling: 'mean', normalize: true });
|
|
const vector = Array.from(result.data);
|
|
return vector;
|
|
}
|
|
|
|
module.exports = {
|
|
getTransformersVector,
|
|
}
|