mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: use cache
This commit is contained in:
parent
6de740f683
commit
2b2d508ec7
@ -132,9 +132,10 @@ export default class LlmNluHelper
|
|||||||
|
|
||||||
// Perform slot filling in a deterministic way since
|
// Perform slot filling in a deterministic way since
|
||||||
// it's currently a challenging task for the LLMs.
|
// it's currently a challenging task for the LLMs.
|
||||||
const entities = await this.nlpEntityService.findAndPopulate({
|
const entities = await this.nlpEntityService.getNlpEntitiesByLookup([
|
||||||
lookups: { $in: ['keywords', 'pattern'] },
|
'keywords',
|
||||||
});
|
'pattern',
|
||||||
|
]);
|
||||||
|
|
||||||
const slotEntities = this.runDeterministicSlotFilling(text, entities);
|
const slotEntities = this.runDeterministicSlotFilling(text, entities);
|
||||||
|
|
||||||
|
@ -175,4 +175,23 @@ export class NlpEntityService extends BaseService<
|
|||||||
return acc;
|
return acc;
|
||||||
}, new Map());
|
}, new Map());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all NLP entities that declare at least one of the specified
|
||||||
|
* lookup strategies.
|
||||||
|
*
|
||||||
|
* @async
|
||||||
|
* @param lookups - One or more lookup strategies to match
|
||||||
|
* against (e.g., {@link LookupStrategy.keywords}, {@link LookupStrategy.pattern}).
|
||||||
|
* An entity is included in the result if **any** of these strategies is found
|
||||||
|
* in its own `lookups` array.
|
||||||
|
* @returns A promise that resolves to the
|
||||||
|
* collection of matching entities.
|
||||||
|
*/
|
||||||
|
async getNlpEntitiesByLookup(lookups: Lookup[]): Promise<NlpEntityFull[]> {
|
||||||
|
const entities = [...(await this.getNlpMap()).values()];
|
||||||
|
return entities.filter((e) => {
|
||||||
|
return lookups.filter((l) => e.lookups.includes(l)).length > 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user