コード例 #1
0
    def start_synapse_by_name(cls, name, brain=None):
        """
        Start a synapse by it's name
        :param name: Name (Unique ID) of the synapse to launch
        :param brain: Brain instance
        """
        logger.debug(
            "[SynapseLauncher] start_synapse_by_name called with synapse name: %s "
            % name)
        # check if we have found and launched the synapse
        synapse = brain.get_synapse_by_name(synapse_name=name)

        if not synapse:
            raise SynapseNameNotFound(
                "The synapse name \"%s\" does not exist in the brain file" %
                name)
        else:
            # get our singleton LIFO
            lifo_buffer = LIFOBuffer()
            list_synapse_to_process = list()
            new_matching_synapse = MatchedSynapse(matched_synapse=synapse,
                                                  matched_order=None,
                                                  user_order=None)
            list_synapse_to_process.append(new_matching_synapse)
            lifo_buffer.add_synapse_list_to_lifo(list_synapse_to_process)
            return lifo_buffer.execute(is_api_call=True)
コード例 #2
0
ファイル: FlaskAPI.py プロジェクト: aleneum/kalliope
    def run_synapse_by_name(self, synapse_name):
        """
        Run a synapse by its name
        test with curl:
        curl -i --user admin:secret -X POST  http://127.0.0.1:5000/synapses/start/id/say-hello-fr
        :param synapse_name:
        :return:
        """
        # get a synapse object from the name
        synapse_target = BrainLoader().get_brain().get_synapse_by_name(
            synapse_name=synapse_name)

        if synapse_target is None:
            data = {"synapse name not found": "%s" % synapse_name}
            return jsonify(error=data), 404
        else:
            # generate a MatchedSynapse from the synapse
            matched_synapse = MatchedSynapse(matched_synapse=synapse_target)
            # get the current LIFO buffer
            lifo_buffer = LIFOBuffer()
            # this is a new call we clean up the LIFO
            lifo_buffer.clean()
            lifo_buffer.add_synapse_list_to_lifo([matched_synapse])
            response = lifo_buffer.execute(is_api_call=True)
            data = jsonify(response)
            return data, 201
コード例 #3
0
ファイル: NeuronModule.py プロジェクト: tet102/kalliope
    def run_synapse_by_name(synapse_name,
                            user_order=None,
                            synapse_order=None,
                            high_priority=False,
                            is_api_call=False,
                            overriding_parameter_dict=None):
        """
        call the lifo for adding a synapse to execute in the list of synapse list to process
        :param synapse_name: The name of the synapse to run
        :param user_order: The user order
        :param synapse_order: The synapse order
        :param high_priority: If True, the synapse is executed before the end of the current synapse list
        :param is_api_call: If true, the current call comes from the api
        :param overriding_parameter_dict: dict of value to add to neuron parameters
        """
        synapse = BrainLoader().get_brain().get_synapse_by_name(synapse_name)
        matched_synapse = MatchedSynapse(
            matched_synapse=synapse,
            matched_order=synapse_order,
            user_order=user_order,
            overriding_parameter=overriding_parameter_dict)

        list_synapse_to_process = list()
        list_synapse_to_process.append(matched_synapse)
        # get the singleton
        lifo_buffer = LIFOBuffer()
        lifo_buffer.add_synapse_list_to_lifo(list_synapse_to_process,
                                             high_priority=high_priority)
        lifo_buffer.execute(is_api_call=is_api_call)
コード例 #4
0
    def run_matching_synapse_from_order(cls,
                                        order_to_process,
                                        brain,
                                        settings,
                                        is_api_call=False,
                                        no_voice=False):
        """
        
        :param order_to_process: the spoken order sent by the user
        :param brain: Brain object
        :param settings: Settings object
        :param is_api_call: if True, the current call come from the API. This info must be known by launched Neuron
        :param no_voice: If true, the generated text will not be processed by the TTS engine
        :return: list of matched synapse
        """

        # get our singleton LIFO
        lifo_buffer = LIFOBuffer()

        # if the LIFO is not empty, so, the current order is passed to the current processing synapse as an answer
        if len(lifo_buffer.lifo_list) > 0:
            # the LIFO is not empty, this is an answer to a previous call
            return lifo_buffer.execute(answer=order_to_process,
                                       is_api_call=is_api_call,
                                       no_voice=no_voice)

        else:  # the LIFO is empty, this is a new call
            # get a list of matched synapse from the order
            list_synapse_to_process = OrderAnalyser.get_matching_synapse(
                order=order_to_process, brain=brain)

            if not list_synapse_to_process:  # the order analyser returned us an empty list
                # add the default synapse if exist into the lifo
                if settings.default_synapse:
                    logger.debug(
                        "[SynapseLauncher] No matching Synapse-> running default synapse "
                    )
                    # get the default synapse
                    default_synapse = brain.get_synapse_by_name(
                        settings.default_synapse)
                    new_matching_synapse = MatchedSynapse(
                        matched_synapse=default_synapse,
                        matched_order=None,
                        user_order=order_to_process)
                    list_synapse_to_process.append(new_matching_synapse)
                else:
                    logger.debug(
                        "[SynapseLauncher] No matching Synapse and no default synapse "
                    )

            lifo_buffer.add_synapse_list_to_lifo(list_synapse_to_process)
            lifo_buffer.api_response.user_order = order_to_process

            return lifo_buffer.execute(is_api_call=is_api_call,
                                       no_voice=no_voice)
コード例 #5
0
    def run_synapse_by_name(self, synapse_name):
        """
        Run a synapse by its name
        test with curl:
        curl -i --user admin:secret -X POST  http://127.0.0.1:5000/synapses/start/id/say-hello-fr

        run a synapse without making kalliope speaking
        curl -i -H "Content-Type: application/json" --user admin:secret -X POST  \
        -d '{"no_voice":"true"}' http://127.0.0.1:5000/synapses/start/id/say-hello-fr

        Run a synapse by its name and pass order's parameters
        curl -i -H "Content-Type: application/json" --user admin:secret -X POST  \
        -d '{"no_voice":"true", "parameters": {"parameter1": "value1" }}' \
        http://127.0.0.1:5000/synapses/start/id/say-hello-fr

        :param synapse_name: name(id) of the synapse to execute
        :return:
        """
        # get a synapse object from the name
        logger.debug("[FlaskAPI] run_synapse_by_name: synapse name -> %s" %
                     synapse_name)
        synapse_target = BrainLoader().get_brain().get_synapse_by_name(
            synapse_name=synapse_name)

        # get no_voice_flag if present
        no_voice = self.get_boolean_flag_from_request(
            request, boolean_flag_to_find="no_voice")

        # get parameters
        parameters = self.get_parameters_from_request(request)

        if synapse_target is None:
            data = {"synapse name not found": "%s" % synapse_name}
            return jsonify(error=data), 404
        else:
            # generate a MatchedSynapse from the synapse
            matched_synapse = MatchedSynapse(matched_synapse=synapse_target,
                                             overriding_parameter=parameters)
            # get the current LIFO buffer
            lifo_buffer = LIFOBuffer()
            # this is a new call we clean up the LIFO
            lifo_buffer.clean()
            lifo_buffer.add_synapse_list_to_lifo([matched_synapse])
            response = lifo_buffer.execute(is_api_call=True, no_voice=no_voice)
            data = jsonify(response)
            return data, 201