Compare commits
3 Commits
d97f0a4c4d
...
75372ad0cc
Author | SHA1 | Date |
---|---|---|
Cohee | 75372ad0cc | |
Cohee | d1f292f462 | |
joenunezb | 890cf81627 |
|
@ -287,8 +287,10 @@ async function synchronizeChat(batchSize = 5) {
|
|||
}
|
||||
}
|
||||
|
||||
// Cache object for storing hash values
|
||||
const hashCache = {};
|
||||
/**
|
||||
* @type {Map<string, number>} Cache object for storing hash values
|
||||
*/
|
||||
const hashCache = new Map();
|
||||
|
||||
/**
|
||||
* Gets the hash value for a given string
|
||||
|
@ -297,15 +299,15 @@ const hashCache = {};
|
|||
*/
|
||||
function getStringHash(str) {
|
||||
// Check if the hash is already in the cache
|
||||
if (Object.hasOwn(hashCache, str)) {
|
||||
return hashCache[str];
|
||||
if (hashCache.has(str)) {
|
||||
return hashCache.get(str);
|
||||
}
|
||||
|
||||
// Calculate the hash value
|
||||
const hash = calculateHash(str);
|
||||
|
||||
// Store the hash in the cache
|
||||
hashCache[str] = hash;
|
||||
hashCache.set(str, hash);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
|
|
@ -325,7 +325,7 @@ router.post('/generate', jsonParser, async function (request, response) {
|
|||
|
||||
// Map InfermaticAI response to OAI completions format
|
||||
if (apiType === TEXTGEN_TYPES.INFERMATICAI) {
|
||||
data['choices'] = (data?.choices || []).map(choice => ({ text: choice.message.content }));
|
||||
data['choices'] = (data?.choices || []).map(choice => ({ text: choice?.message?.content || choice.text }));
|
||||
}
|
||||
|
||||
return response.send(data);
|
||||
|
|
|
@ -5,7 +5,10 @@ const TASK = 'text-classification';
|
|||
|
||||
const router = express.Router();
|
||||
|
||||
const cacheObject = {};
|
||||
/**
|
||||
* @type {Map<string, object>} Cache for classification results
|
||||
*/
|
||||
const cacheObject = new Map();
|
||||
|
||||
router.post('/labels', jsonParser, async (req, res) => {
|
||||
try {
|
||||
|
@ -23,15 +26,20 @@ router.post('/', jsonParser, async (req, res) => {
|
|||
try {
|
||||
const { text } = req.body;
|
||||
|
||||
/**
|
||||
* Get classification result for a given text
|
||||
* @param {string} text Text to classify
|
||||
* @returns {Promise<object>} Classification result
|
||||
*/
|
||||
async function getResult(text) {
|
||||
if (Object.hasOwn(cacheObject, text)) {
|
||||
return cacheObject[text];
|
||||
if (cacheObject.has(text)) {
|
||||
return cacheObject.get(text);
|
||||
} else {
|
||||
const module = await import('../transformers.mjs');
|
||||
const pipe = await module.default.getPipeline(TASK);
|
||||
const result = await pipe(text, { topk: 5 });
|
||||
result.sort((a, b) => b.score - a.score);
|
||||
cacheObject[text] = result;
|
||||
cacheObject.set(text, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue