Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates logging around language plugin errors #171

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 42 additions & 27 deletions ovos_plugin_manager/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def get_lang_detect_module_configs(module_name: str):


class OVOSLangDetectionFactory:
""" replicates the base neon class, but uses only OPM enabled plugins"""
"""
replicates the base neon class, but uses only OPM enabled plugins
"""
MAPPINGS = {
"libretranslate": "libretranslate_detection_plug",
"google": "googletranslate_detection_plug",
Expand All @@ -116,37 +118,44 @@ class OVOSLangDetectionFactory:

@staticmethod
def create(config=None):
"""Factory method to create a LangDetection engine based on configuration.
"""
Factory method to create a LangDetection engine based on configuration

The configuration file ``mycroft.conf`` contains a ``language`` section with
The configuration file `mycroft.conf` contains a `language` section with
the name of a LangDetection module to be read by this method.

"language": {
"language": {
"detection_module": <engine_name>
}
}
"""
config = config or Configuration()
if "language" in config:
config = config["language"]
lang_module = config.get("detection_module")
if not lang_module:
# TODO: `language` is the only factory with this special handling
LOG.warning("`detection_module` not configured")
lang_module = "ovos-lang-detect-ngram-lm"
try:
config = config or Configuration()
if "language" in config:
config = config["language"]
lang_module = config.get("detection_module", "libretranslate_detection_plug")
if lang_module in OVOSLangDetectionFactory.MAPPINGS:
lang_module = OVOSLangDetectionFactory.MAPPINGS[lang_module]

clazz = load_lang_detect_plugin(lang_module)
if clazz is None:
raise ValueError
raise ValueError(f"Failed to load module: {lang_module}")
LOG.info(f'Loaded the Language Detection plugin {lang_module}')
return clazz(config=get_plugin_config(config, "language", lang_module))
return clazz(config=get_plugin_config(config, "language",
lang_module))
except Exception:
# The Language Detection backend failed to start, fall back if appropriate.
if lang_module != "libretranslate_detection_plug":
lang_module = "libretranslate_detection_plug"
LOG.error(f'Language Translation plugin {lang_module} not found\n'
LOG.error(f'Language Detection plugin {lang_module} not found. '
f'Falling back to libretranslate plugin')
clazz = load_tx_plugin("libretranslate_detection_plug")
if clazz:
return clazz(config=get_plugin_config(config, "language", lang_module))
return clazz(config=get_plugin_config(config, "language",
lang_module))

raise

Expand All @@ -163,36 +172,42 @@ class OVOSLangTranslationFactory:
# TODO - get_class method
@staticmethod
def create(config=None):
"""Factory method to create a LangTranslation engine based on configuration.
"""
Factory method to create a LangTranslation engine based on configuration

The configuration file ``mycroft.conf`` contains a ``language`` section with
The configuration file `mycroft.conf` contains a `language` section with
the name of a LangDetection module to be read by this method.


"language": {
"language": {
"translation_module": <engine_name>
}
}
"""
config = config or Configuration()
if "language" in config:
config = config["language"]
lang_module = config.get("translation_module")
if not lang_module:
# TODO: `language` is the only factory with this special handling
LOG.warning("`translation_module` not configured")
lang_module = "libretranslate_plug"
try:
config = config or Configuration()
if "language" in config:
config = config["language"]
lang_module = config.get("translation_module", "libretranslate_plug")
if lang_module in OVOSLangTranslationFactory.MAPPINGS:
lang_module = OVOSLangTranslationFactory.MAPPINGS[lang_module]
clazz = load_tx_plugin(lang_module)
if clazz is None:
raise ValueError
raise ValueError(f"Failed to load module: {lang_module}")
LOG.info(f'Loaded the Language Translation plugin {lang_module}')
return clazz(config=get_plugin_config(config, "language", lang_module))
return clazz(config=get_plugin_config(config, "language",
lang_module))
except Exception:
# The Language Detection backend failed to start, fall back if appropriate.
if lang_module != "libretranslate_plug":
lang_module = "libretranslate_plug"
LOG.error(f'Language Translation plugin {lang_module} not found\n'
f'Falling back to libretranslate plugin')
LOG.error(f'Language Translation plugin {lang_module} '
f'not found. Falling back to libretranslate plugin')
clazz = load_tx_plugin("libretranslate_plug")
if clazz:
return clazz(config=get_plugin_config(config, "language", lang_module))
return clazz(config=get_plugin_config(config, "language",
lang_module))

raise
Loading