from core.builtin_concepts import BuiltinConcepts import core.builtin_helpers from evaluators.BaseEvaluator import AllReturnValuesEvaluator, BaseEvaluator import logging from parsers.BaseParser import BaseParser log = logging.getLogger(__name__) class TooManySuccessEvaluator(AllReturnValuesEvaluator): """ Used to filter the responses It has a low priority to let other evaluators try to resolve the errors """ NAME = "TooManySuccess" def __init__(self): super().__init__(self.NAME, 10) self.success = [] def matches(self, context, return_values): sheerka = context.sheerka after_evaluation = False nb_successful_evaluators = 0 only_parsers_in_error = True unlisted = False for ret in return_values: if sheerka.isinstance(ret.value, BuiltinConcepts.AFTER_EVALUATION): if ret.status: after_evaluation = True elif ret.who.startswith(BaseEvaluator.PREFIX): if ret.status: nb_successful_evaluators += 1 self.success.append(ret) elif ret.who.startswith(BaseParser.PREFIX): if ret.status: only_parsers_in_error = False else: unlisted = True return after_evaluation and nb_successful_evaluators > 1 and only_parsers_in_error and not unlisted def eval(self, context, return_values): sheerka = context.sheerka if not core.builtin_helpers.is_same_success(sheerka, self.success): too_many_success = sheerka.new(BuiltinConcepts.TOO_MANY_SUCCESS, obj=self.success) return sheerka.ret(self.name, False, too_many_success, parents=return_values) return None