Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(speech): keep the plain download hint for a Whisper model never downloaded (#860)

Ruben Lütkec923d33fce8b
diff --git a/dodaios/speech/local_models.py b/dodaios/speech/local_models.py
index 5931e1abea..1255490d9c 100644
--- a/dodaios/speech/local_models.py
+++ b/dodaios/speech/local_models.py
@@ -66,6 +66,9 @@ _WHISPER_MODEL_ALLOW_PATTERNS = (
"vocabulary.*",
)
_WHISPER_MODEL_REQUIRED_FILES = ("config.json", "model.bin", "tokenizer.json")
+# Cache issue for a checkpoint that was never downloaded: the common first-run
+# state, which gets the plain "download it once" sentence instead of a file list.
+_WHISPER_NOT_DOWNLOADED = "the model has not been downloaded yet"
#: Runtime id -> module to probe. A runtime the app does not know about is
#: reported absent rather than guessed at.
@@ -264,7 +267,7 @@ def _whisper_model_cache_issue(name: str) -> str | None:
if "/" not in name:
spec = importlib.util.find_spec("faster_whisper")
if spec is None or spec.origin is None:
- return False
+ return "the faster-whisper runtime could not be located"
source = Path(spec.origin).with_name("utils.py").read_text(encoding="utf-8")
aliases = {}
for node in ast.parse(source).body:
@@ -278,14 +281,19 @@ def _whisper_model_cache_issue(name: str) -> str | None:
if not isinstance(repo_id, str) or not repo_id:
return "the model name is not available in the installed faster-whisper runtime"
from huggingface_hub import snapshot_download
-
- directory = Path(
- snapshot_download(
- repo_id,
- local_files_only=True,
- allow_patterns=list(_WHISPER_MODEL_ALLOW_PATTERNS),
+ from huggingface_hub.errors import LocalEntryNotFoundError
+
+ try:
+ directory = Path(
+ snapshot_download(
+ repo_id,
+ local_files_only=True,
+ allow_patterns=list(_WHISPER_MODEL_ALLOW_PATTERNS),
+ )
)
- )
+ except LocalEntryNotFoundError:
+ log.debug("Whisper checkpoint %r has not been downloaded yet", name)
+ return _WHISPER_NOT_DOWNLOADED
# A snapshot directory alone can be a partial download. The tokenizer
# must also be local, otherwise the recognizer fetches one during boot.
missing = [
@@ -373,6 +381,11 @@ def whisper_status(model: str) -> LocalModelStatus:
"The local speech engine is not installed yet. Install it from here "
"to transcribe on this machine without an API key."
)
+ elif cache_issue == _WHISPER_NOT_DOWNLOADED:
+ detail = (
+ f"The engine is installed, but the {model} model still has to be "
+ "downloaded (about 3 GB, once)."
+ )
elif cache_issue is not None:
detail = f"The engine is installed, but the {model} model is not ready: {cache_issue}."
else:
diff --git a/tests/unit/speech/test_local_models.py b/tests/unit/speech/test_local_models.py
index 052448f97c..d896bbe2a8 100644
--- a/tests/unit/speech/test_local_models.py
+++ b/tests/unit/speech/test_local_models.py
@@ -164,3 +164,35 @@ def test_status_reports_the_model_the_config_actually_names(
assert status is not None
assert status.model_label == "small"
assert "small" in status.detail
+
+
+def test_never_downloaded_model_gets_the_plain_download_sentence(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """A first run is not a broken cache: tell the user to download once."""
+ monkeypatch.setattr(local_models, "runtime_installed", lambda runtime: True)
+ monkeypatch.setattr(
+ local_models,
+ "_whisper_model_cache_issue",
+ lambda name: local_models._WHISPER_NOT_DOWNLOADED,
+ )
+
+ status = local_models.whisper_status("large-v3")
+
+ assert status.ready is False
+ assert "still has to be downloaded" in status.detail
+
+
+def test_uncached_repo_reads_as_not_downloaded(monkeypatch: pytest.MonkeyPatch) -> None:
+ import huggingface_hub
+ from huggingface_hub.errors import LocalEntryNotFoundError
+
+ def _missing(*_args, **_kwargs):
+ raise LocalEntryNotFoundError("not cached")
+
+ monkeypatch.setattr(huggingface_hub, "snapshot_download", _missing)
+
+ assert (
+ local_models._whisper_model_cache_issue("Systran/faster-whisper-large-v3")
+ == local_models._WHISPER_NOT_DOWNLOADED
+ )