UNPKG

asksuite-core

Version:
65 lines (57 loc) 1.91 kB
const Util = require('../util'); const { ErrorHandlerService } = require('./ErrorHandlerService'); class KeyMatcherAccessor { constructor(awsLambdaCaller, openAiEnabled = false) { this.awsLambdaCaller = awsLambdaCaller; this.openAiEnabled = openAiEnabled; } resolveText(request) { let intent = null; return new Promise(resolve => { const executor = async () => { try { // KeyMatcher intent = await this.awsLambdaCaller.call(request, 'asksuite-NLP-dev-keyMatcherNLP'); if (!intent || !intent.intent) { throw new Error('Intent not present in response: \n' + JSON.stringify(intent)); } if (this.openAiEnabled || Util.isQuote(intent.intent)) { const processingStep = intent.processingStep || { text: request.text, intentFound: intent.intent, }; intent = { ...request.findIntent, processingStep: { language: request.language, resolver: 'KEY_MATCHER', processingStep: { ...processingStep, fallbackReason: this.openAiEnabled ? 'openai_enabled' : 'ignored_quotation_result', }, }, }; } } catch (e) { const errorData = ErrorHandlerService.accessorErrorHandler(e); intent = { processingStep: { fallbackReason: 'intent_not_found', intentFound: null, text: request.text, language: request.language, resolver: 'KEY_MATCHER', errorData, }, }; console.log('Erro no keymatcher ', e); } resolve(intent); }; executor(); }); } } module.exports = KeyMatcherAccessor;