示例#1
0
    def maybe_get_dialogue_obj(self, chat: Tuple[str, str]) -> Optional[DialogueObject]:
        """Process a chat and maybe modify the dialogue stack.

        Args:
            chat (Tuple[str, str]): Incoming chat from a player.
                Format is (speaker, chat), eg. ("player1", "build a red house")

        Returns:
            DialogueObject or empty if no action is needed.

        """

        if len(self.dialogue_stack) > 0 and self.dialogue_stack[-1].awaiting_response:
            return None

        # chat is a single line command
        speaker, chatstr = chat
        preprocessed_chatstrs = preprocess.preprocess_chat(chatstr)

        # Push appropriate DialogueObjects to stack if incoming chat
        # is one of the scripted ones
        for greeting_type in self.botGreetings:
            if any([chat in self.botGreetings[greeting_type] for chat in preprocessed_chatstrs]):
                return BotGreet(greeting_type, **self.dialogue_object_parameters)

        # NOTE: preprocessing in model code is different, this shouldn't break anything
        logical_form = self.get_logical_form(s=preprocessed_chatstrs[0], model=self.model)
        return self.handle_logical_form(speaker, logical_form, preprocessed_chatstrs[0])
示例#2
0
    def run_model(self, chat: Tuple[str, str]) -> Optional[DialogueObject]:
        """Process a chat and maybe modify the dialogue stack"""

        if chat[1] == "ipdb":
            ipdb.set_trace()

        if len(self.dialogue_stack
               ) > 0 and self.dialogue_stack[-1].awaiting_response:
            return None

        # chat is a single line command
        speaker, chatstr = chat
        preprocessed_chatstrs = preprocess.preprocess_chat(chatstr)

        # Push appropriate DialogueObjects to stack if incomign chat
        # is one of the scripted ones
        if any([
                chat in self.botCapabilityQuery
                for chat in preprocessed_chatstrs
        ]):
            return BotCapabilities(**self.dialogue_object_parameters)
        if any([chat in self.botGreetings for chat in preprocessed_chatstrs]):
            return BotGreet(**self.dialogue_object_parameters)
        if any(["debug_remove" in chat for chat in preprocessed_chatstrs]):
            return BotVisionDebug(**self.dialogue_object_parameters)

        # Assume non-compound command for now
        action_dict = self.ttad(preprocessed_chatstrs[0])
        return self.handle_action_dict(speaker, action_dict)
    def maybe_get_dialogue_obj(
            self, chat: Tuple[str, str]) -> Optional[DialogueObject]:
        """Process a chat and maybe modify the dialogue stack"""

        if len(self.dialogue_stack
               ) > 0 and self.dialogue_stack[-1].awaiting_response:
            return None

        # chat is a single line command
        speaker, chatstr = chat
        preprocessed_chatstrs = preprocess.preprocess_chat(chatstr)

        # Push appropriate DialogueObjects to stack if incomign chat
        # is one of the scripted ones
        if any([
                chat in self.botCapabilityQuery
                for chat in preprocessed_chatstrs
        ]):
            return BotCapabilities(**self.dialogue_object_parameters)
        for greeting_type in self.botGreetings:
            if any([
                    chat in self.botGreetings[greeting_type]
                    for chat in preprocessed_chatstrs
            ]):
                return BotGreet(greeting_type,
                                **self.dialogue_object_parameters)

        # NOTE: preprocessing in model code is different, this shouldn't break anything
        logical_form = self.get_logical_form(s=preprocessed_chatstrs[0],
                                             model=self.model)
        return self.handle_logical_form(speaker, logical_form,
                                        preprocessed_chatstrs[0])