Ejemplo n.º 1
0
 def render(self) -> Dict[LanguageCode, dict]:
     languages: List[LanguageCode] = agent_supported_languages(self.agent_cls)
     result = {}
     for lang in languages:
         rendered = self.render_agent(lang)
         rendered.interactionModel.languageModel.intents.extend(DEFAULT_INTENTS)
         result[lang] = asdict(rendered, dict_factory=custom_asdict_factory())
     return result
Ejemplo n.º 2
0
def render(connector: SnipsConnector) -> Dict[LanguageCode, dict]:
    languages: List[LanguageCode] = agent_supported_languages(connector.agent_cls)
    result = {}
    for lang in languages:
        try:
            rendered = render_dataset(connector, lang)
            result[lang] = asdict(rendered, dict_factory=custom_asdict_factory())
        except NotImplementedError as exc:
            logger.error("Could not export Agent for language %s: %s", lang, exc)
    return result
Ejemplo n.º 3
0
 def __init__(self,
              agent_cls: Type[Agent],
              default_session: str = None,
              default_language: Union[LanguageCode, str] = None):
     super().__init__(agent_cls, default_session, default_language)
     self.nlu_engines = {
         lang: snips_nlu.SnipsNLUEngine()
         for lang in agent_supported_languages(agent_cls)
     }
     self.prediction_component = SnipsPredictionComponent(
         agent_cls, self.entity_mappings)
Ejemplo n.º 4
0
    def __init__(self,
                 agent_cls: type(Agent),
                 default_session: str = None,
                 default_language: Union[LanguageCode, str] = None):
        if not default_language:
            default_language = agent_supported_languages(agent_cls)[0]
        default_language = ensure_language_code(default_language)

        if not default_session:
            default_session = f"py-{str(uuid1())}"

        self.agent_cls = agent_cls
        self.default_session = default_session
        self.default_language = default_language
Ejemplo n.º 5
0
    def __new__(cls, name, bases, dct):
        result_cls = super().__new__(cls, name, bases, dct)

        if name == 'Agent':
            assert not bases
            return result_cls

        if not result_cls.languages:
            result_cls.languages = language.agent_supported_languages(
                result_cls)

        languages = []
        for lan in result_cls.languages:
            if isinstance(lan, LanguageCode):
                languages.append(lan)
            elif isinstance(lan, str):
                languages.append(LanguageCode(lan))
            else:
                raise ValueError(
                    f"Unsupported language '{lan}' for Agent '{result_cls}'. Must be a value of 'intents.LanguageCode'"
                )
        result_cls.languages = languages

        return result_cls