def create_processor( self, preprocessor: Optional[Callable[[Text], Text]] = None) -> MessageProcessor: """Instantiates a processor based on the set state of the agent.""" # Checks that the interpreter and tracker store are set and # creates a processor if not self.is_ready(): raise AgentNotReady( "Agent needs to be prepared before usage. You need to set an " "interpreter and a tracker store.") return MessageProcessor( self.interpreter, self.policy_ensemble, self.domain, self.tracker_store, self.nlg, action_endpoint=self.action_endpoint, message_preprocessor=preprocessor, )
def persist(self, model_path: Text, dump_flattened_stories: bool = False) -> None: """Persists this agent into a directory for later loading and usage.""" if dump_flattened_stories: raise_warning( "The `dump_flattened_stories` argument will be removed from " "`Agent.persist` in the 2.0 release. Please dump your " "training data separately if you need it to be part of the model.", FutureWarning, ) if not self.is_core_ready(): raise AgentNotReady("Can't persist without a policy ensemble.") if not model_path.endswith(DEFAULT_CORE_SUBDIRECTORY_NAME): model_path = os.path.join(model_path, DEFAULT_CORE_SUBDIRECTORY_NAME) self._clear_model_directory(model_path) self.policy_ensemble.persist(model_path, dump_flattened_stories) self.domain.persist(os.path.join(model_path, DEFAULT_DOMAIN_PATH)) self.domain.persist_specification(model_path) logger.info("Persisted model to '{}'".format(os.path.abspath(model_path)))
def decorated(self: Agent, *args: Any, **kwargs: Any) -> Any: if not self.is_ready(): raise AgentNotReady( "Agent needs to be prepared before usage. You need to set a " "processor and a tracker store.") return f(self, *args, **kwargs)