Пример #1
0
def _draw_tail(entropy, history):
    buttons_frame = ButtonsFrame(text="")
    buttons_frame.add_button(Button('More', "@next:"+str(len(history)-1)))
    caption = "Press More "

    if entropy:
        caption += "specify a " + entropy[0][1]
        for ent_value in entropy[0][2][:4]:
            button_a = Button(ent_value[0], f'@entropy:{len(history)-1}:{entropy[0][1]}:{ent_value[0]}')
            buttons_frame.add_button(button_a)

    buttons_frame.text = caption
    return buttons_frame
Пример #2
0
def _draw_item(item, idx, history):
    title = item['Title']
    if 'ListPrice' in item:
        title += " - **$" + item['ListPrice'].split('$')[1]+"**"

    buttons_frame = ButtonsFrame(text=title)
    buttons_frame.add_button(Button('Show details', "@details:"+str(len(history)-2)+":"+str(idx)))
    return buttons_frame
Пример #3
0
    def _call(self,
              utterances_batch: list,
              utterances_ids: list = None) -> list:
        """Processes batch of utterances and returns corresponding responses batch.

        Args:
            utterances: Batch of incoming 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_ in zip(utterances_batch, utterances_ids):

            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":
                    rich_message.add_control(
                        PlainText(
                            show_details(self.history[id_][int(
                                parts[0])][0][int(parts[1])])))
                    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

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

            responses, confidences, state = self.skills[0]([utt],
                                                           self.history[id_],
                                                           [self.states[id_]])

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

            items, entropy, total = responses

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

            for idx, item in enumerate(items):

                title = item['Title']
                if 'ListPrice' in item:
                    title += " - **$" + item['ListPrice'].split('$')[1] + "**"

                buttons_frame = ButtonsFrame(text=title)
                buttons_frame.add_button(
                    Button(
                        'Show details', "@details:" +
                        str(len(self.history[id_]) - 2) + ":" + str(idx)))
                rich_message.add_control(buttons_frame)

            buttons_frame = ButtonsFrame(text="")
            if self.states[id_]["start"] > 0:
                buttons_frame.add_button(
                    Button('Previous',
                           "@previous:" + str(len(self.history[id_]) - 1)))

            buttons_frame.add_button(
                Button('Next', "@next:" + str(len(self.history[id_]) - 1)))
            rich_message.add_control(buttons_frame)

            if entropy:
                buttons_frame = ButtonsFrame(text="Please specify a " +
                                             entropy[0][1])
                for ent_value in entropy[0][2][:3]:
                    button_a = Button(
                        ent_value[0],
                        f'@entropy:{len(self.history[id_])-1}:{entropy[0][1]}:{ent_value[0]}'
                    )

                    buttons_frame.add_button(button_a)

                rich_message.add_control(buttons_frame)

        return [rich_message]