Skip to content

refactor(platform): extract model-file downloads from internal/audio - #1259

Merged
edenreich merged 3 commits into
mainfrom
refactor/platform-model-downloads
Sep 21, 2026
Merged

edenreich merged 3 commits into
mainfrom
refactor/platform-model-downloads

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Moves model-file downloading out of internal/audio into internal/platform, so a capability that is not audio can fetch models from Hugging Face without importing the speech package. Pure refactor: same URLs requested, same cache paths, same progress messages, same error strings. Prerequisite for #1257.

Closes #1258

Changes

  • internal/platform/download (moved from internal/audio/download.go with its tests, history preserved): ToFile (atomic temp file + rename, Content-Length check) and NewProgressReader. It is its own package because BinaryManager uses the progress reader for GitHub release assets, which have nothing to do with Hugging Face.
  • internal/platform/huggingface (new): Repo{ID, Revision}, Client{BaseURL, HTTP}, EnsureFile and ErrNotCached. It is now the only non-test file containing huggingface.co or /resolve/. An empty Revision resolves to main; a commit SHA pins the files.
  • internal/audio/model.go and ttsmodel.go: the hardcoded huggingFaceWhisperBase / qwen3TTSBase URLs and the duplicated stat, auto_download check, mkdir, download sequence are gone. They keep what is speech knowledge: modelFileName, ttsModelFiles and its quant-suffix rule, modelsDir, and the speech_to_text.auto_download is disabled / text_to_speech.auto_download is disabled messages, produced by wrapping ErrNotCached. Public types, constructors and methods are unchanged.
  • internal/audio/binary.go: uses download.NewProgressReader; otherwise untouched.
  • Tests: model_test.go and synthesizer_test.go only change their wiring (m.hub = &huggingface.Client{BaseURL: srv.URL, HTTP: srv.Client()}), and their test servers now assert the full /<repo>/resolve/main/<file> path, so the requested URLs are pinned by tests. New huggingface tests cover: cached file makes no request, missing without download returns ErrNotCached and does not create the dir, download lands in dir/file, empty revision resolves to main, a non-200 leaves nothing behind.

Dependency direction: internal/platform/* does not import internal/audio. task precommit:run (0 lint issues, imports check) and task test (94 packages) pass.

Not in this PR: resume or retry for large downloads, moving BinaryManager, any avatar code.

no docs ticket: internal-only refactor

Move the atomic download and progress reader to internal/platform/download, and the Hugging Face URL shape plus the ensure-cached sequence to internal/platform/huggingface. internal/audio keeps which files a model is and the auto_download policy with its error text. No behaviour change.

Refs #1258
@edenreich
edenreich marked this pull request as ready for review September 21, 2026 22:02
@edenreich
edenreich requested a review from a team as a code owner September 21, 2026 22:02
Comment thread internal/platform/download/download.go Resolved
@edenreich
edenreich merged commit c66cb44 into main Sep 21, 2026
1 check passed
@edenreich
edenreich deleted the refactor/platform-model-downloads branch September 21, 2026 22:13
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.205.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TASK] Refactor extract model-file downloads from internal/audio into internal/platform

1 participant