deeppavlov/agents/ecommerce_agent/ecommerce_agent.py
def _call(self, utterances_batch: List[str], utterances_ids: List[int] = None) -> List[RichMessage]:
        """Processes batch of utterances and returns corresponding responses batch.

        Args:
            utterances_batch: Batch of incoming utterances.
            utterances_ids: Batch of dialog IDs corresponding to incoming utterances.

        Returns:
            responses: A batch of responses corresponding to the
                utterance batch received by agent.
        """

        rich_message = RichMessage()
        for utt_id, utt in enumerate(utterances_batch):

            if utterances_ids:
                id_ = utterances_ids[utt_id]

            log.debug(f'Utterance: {utt}')

            if utt == "/start":
                welcome = "I am a new e-commerce bot. I will help you to find products that you are looking for. Please type your request in plain text."
                rich_message.add_control(PlainText(welcome))
                continue

            if utt[0] == "@":
                command, *parts = utt.split(":")
                log.debug(f'Actions: {parts}')

                if command == "@details":
                    batch_index = int(parts[0])  # batch index in history list
                    item_index = int(parts[1])  # index in batch
                    rich_message.add_control(PlainText(show_details(
                        self.history[id_][batch_index][item_index])))
                    continue

                if command == "@entropy":
                    state = self.history[id_][int(parts[0])]
                    state[parts[1]] = parts[2]
                    state["start"] = 0
                    state["stop"] = 5
                    utt = state['query']
                    self.states[id_] = state

                if command == "@next":
                    state = self.history[id_][int(parts[0])]
                    state['start'] = state['stop']
                    state['stop'] = state['stop'] + 5
                    utt = state['query']
                    self.states[id_] = state
            else:
                if id_ not in self.states:
                    self.states[id_] = {}

                self.states[id_]["start"] = 0
                self.states[id_]["stop"] = 5

            responses_batch, confidences_batch, state_batch = self.skills[0](
                [utt], self.history[id_], [self.states[id_]])

            # update `self.states` with retrieved results
            self.states[id_] = state_batch[0]
            self.states[id_]["query"] = utt

            items_batch, entropy_batch = responses_batch

            for batch_idx, items in enumerate(items_batch):

                self.history[id_].append(items)
                self.history[id_].append(self.states[id_])

                for idx, item in enumerate(items):
                    rich_message.add_control(_draw_item(item, idx, self.history[id_]))

                if len(items) == self.states[id_]['stop'] - self.states[id_]['start']:
                    buttons_frame = _draw_tail(entropy_batch[batch_idx], self.history[id_])
                    rich_message.add_control(buttons_frame)

        return [rich_message]
def _call(self, utterances_batch: List[str], utterances_ids: List[int] = None) -> List[RichMessage]:
        """Processes batch of utterances and returns corresponding responses batch.

        Args:
            utterances_batch: Batch of incoming utterances.
            utterances_ids: Batch of dialog IDs corresponding to incoming utterances.

        Returns:
            responses: A batch of responses corresponding to the
                utterance batch received by agent.
        """

        rich_message = RichMessage()
        for utt_id, utt in enumerate(utterances_batch):

            if utterances_ids:
                id_ = utterances_ids[utt_id]

            log.debug(f'Utterance: {utt}')

            if utt == "/start":
                welcome = "I am a new e-commerce bot. I will help you to find products that you are looking for. Please type your request in plain text."
                rich_message.add_control(PlainText(welcome))
                continue

            if utt[0] == "@":
                command, *parts = utt.split(":")
                log.debug(f'Actions: {parts}')

                if command == "@details":
                    batch_index = int(parts[0])  # batch index in history list
                    item_index = int(parts[1])  # index in batch
                    rich_message.add_control(PlainText(show_details(
                        self.history[id_][batch_index][item_index])))
                    continue

                if command == "@entropy":
                    state = self.history[id_][int(parts[0])]
                    state[parts[1]] = parts[2]
                    state["start"] = 0
                    state["stop"] = 5
                    utt = state['query']
                    self.states[id_] = state

                if command == "@next":
                    state = self.history[id_][int(parts[0])]
                    state['start'] = state['stop']
                    state['stop'] = state['stop'] + 5
                    utt = state['query']
                    self.states[id_] = state
            else:
                if id_ not in self.states:
                    self.states[id_] = {}

                self.states[id_]["start"] = 0
                self.states[id_]["stop"] = 5

            responses_batch, confidences_batch, state_batch = self.skills[0](
                [utt], self.history[id_], [self.states[id_]])

            # update `self.states` with retrieved results
            self.states[id_] = state_batch[0]
            self.states[id_]["query"] = utt

            items_batch, entropy_batch = responses_batch

            for batch_idx, items in enumerate(items_batch):

                self.history[id_].append(items)
                self.history[id_].append(self.states[id_])

                for idx, item in enumerate(items):
                    rich_message.add_control(_draw_item(item, idx, self.history[id_]))

                if len(items) == self.states[id_]['stop'] - self.states[id_]['start']:
                    buttons_frame = _draw_tail(entropy_batch[batch_idx], self.history[id_])
                    rich_message.add_control(buttons_frame)

        return [rich_message]
Processes batch of utterances and returns corresponding responses batch.

        Args:
            utterances_batch: Batch of incoming utterances.
            utterances_ids: Batch of dialog IDs corresponding to incoming utterances.

        Returns:
            responses: A batch of responses corresponding to the
                utterance batch received by agent.