示例#1
0
    def load_from_remote_storage(
        remote_storage: Text,
        model_name: Text,
        interpreter: Optional[NaturalLanguageInterpreter] = None,
        generator: Union[EndpointConfig, NaturalLanguageGenerator] = None,
        tracker_store: Optional[TrackerStore] = None,
        lock_store: Optional[LockStore] = None,
        action_endpoint: Optional[EndpointConfig] = None,
        model_server: Optional[EndpointConfig] = None,
    ) -> Optional["Agent"]:
        from rasa.nlu.persistor import get_persistor

        persistor = get_persistor(remote_storage)

        if persistor is not None:
            target_path = tempfile.mkdtemp()
            persistor.retrieve(model_name, target_path)

            return Agent.load(
                target_path,
                interpreter=interpreter,
                generator=generator,
                tracker_store=tracker_store,
                lock_store=lock_store,
                action_endpoint=action_endpoint,
                model_server=model_server,
                remote_storage=remote_storage,
            )

        return None
示例#2
0
文件: train.py 项目: tgalery/rasa_nlu
def create_persistor(persistor: Optional[Text]):
    """Create a remote persistor to store the model if configured."""

    if persistor is not None:
        from rasa.nlu.persistor import get_persistor
        return get_persistor(persistor)
    else:
        return None
示例#3
0
 def _load_model_from_cloud(self, model_name, target_path):
     try:
         from rasa.nlu.persistor import get_persistor
         p = get_persistor(self.remote_storage)
         if p is not None:
             p.retrieve(model_name, self._project, target_path)
         else:
             raise RuntimeError("Unable to initialize persistor")
     except Exception as e:
         logger.warning("Using default interpreter, couldn't fetch "
                        "model: {}".format(e))
         raise  # re-raise this exception because nothing we can do now
示例#4
0
    def _list_models_in_cloud(self) -> List[Text]:

        try:
            from rasa.nlu.persistor import get_persistor
            p = get_persistor(self.remote_storage)
            if p is not None:
                return p.list_models(self._project)
            else:
                return []
        except Exception as e:
            logger.warning("Failed to list models of project {}. "
                           "{}".format(self._project, e))
            return []
示例#5
0
 def _list_projects_in_cloud(self) -> List[Text]:
     # noinspection PyBroadException
     try:
         from rasa.nlu.persistor import get_persistor
         p = get_persistor(self.remote_storage)
         if p is not None:
             return p.list_projects()
         else:
             return []
     except Exception:
         logger.exception("Failed to list projects. Make sure you have "
                          "correctly configured your cloud storage "
                          "settings.")
         return []
示例#6
0
    def load_from_remote_storage(
        remote_storage: Text, component_builder: ComponentBuilder, model_name: Text
    ) -> "NLUModel":
        from rasa.nlu.persistor import get_persistor

        p = get_persistor(remote_storage)
        if p is not None:
            target_path = tempfile.mkdtemp()
            p.retrieve(model_name, target_path)
            interpreter = interpreter_for_model(component_builder, target_path)

            return NLUModel(model_name, interpreter, target_path)
        else:
            raise RuntimeError("Unable to initialize persistor")
示例#7
0
文件: agent.py 项目: spawn08/rasa
    def load_model_from_remote_storage(self, model_name: Text) -> None:
        """Loads an Agent from remote storage."""
        from rasa.nlu.persistor import get_persistor

        persistor = get_persistor(self.remote_storage)

        if persistor is not None:
            with tempfile.TemporaryDirectory() as temporary_directory:
                persistor.retrieve(model_name, temporary_directory)
                self.load_model(temporary_directory)

        else:
            raise RasaException(
                f"Persistor not found for remote storage: '{self.remote_storage}'."
            )
示例#8
0
def test_raise_exception_in_get_external_persistor():
    with pytest.raises(ImportError):
        _ = persistor.get_persistor("unknown.persistor")
示例#9
0
def test_get_external_persistor():
    p = persistor.get_persistor("tests.nlu.test_persistor.TestPersistor")
    assert isinstance(p, TestPersistor)