Repository navigation
Description
Summary
Move 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: no behaviour, config, flag or output change. It is split out of #1257 (AvatarGeneration), which will be the third caller and the first non-audio one, and it should land first on its own so that PR stays a feature and this one stays a no-op move.
What is wrong today
internal/audio owns three things that are not speech:
download.go:downloadToFile(atomic temp file + rename, Content-Length check) andprogressReader(reports throughagentdomain.ToolProgressCallback). Generic transfer code.- The Hugging Face URL shape, hardcoded twice as
https://huggingface.co/<repo>/resolve/main:huggingFaceWhisperBaseinmodel.goandqwen3TTSBaseinttsmodel.go. - The same "stat, check
auto_download, mkdir, download" sequence, written once inModelManager.EnsureModeland again inTTSModelManager.ensureFile.
binary.go also uses newProgressReader, for GitHub release assets. So the progress reader is not Hugging Face specific either, which is why this is two packages and not one.
Target boundary
Fetching files is a generic subdomain (commodity, no business rules), and per CLAUDE.md "platform/ is shared infrastructure". What a model is stays with the capability that uses it.
| Concern | Lives in | Why |
|---|---|---|
| Atomic download to a file, progress reporting | internal/platform/download |
Used by Hugging Face fetches and by BinaryManager (GitHub releases). Knows nothing about either. |
huggingface.co/<repo>/resolve/<revision>/<file>, ensuring a repo file is cached in a dir |
internal/platform/huggingface |
The anti-corruption layer: the only package that knows how Hugging Face addresses a file. If the URL shape, a mirror or auth ever changes, it changes here. |
Which files a model is: modelFileName (tiny -> ggml-tiny.bin), ttsModelFiles presets and the quant-suffix to mmproj rule |
internal/audio (unchanged) |
Speech knowledge. It must not move to platform. |
Whether a download is allowed (speech_to_text.auto_download, text_to_speech.auto_download) and the error naming that config key |
internal/audio (unchanged) |
Policy and its wording belong to the capability. platform is told, it does not decide. |
Where models are cached (modelsDir) |
internal/audio (unchanged) |
Config of the capability. |
Proposed surface, small on purpose:
// internal/platform/download
func ToFile(ctx context.Context, client *http.Client, url, dstPath, label string) error
func NewProgressReader(ctx context.Context, src io.Reader, label string, total int64) io.Reader
// internal/platform/huggingface
type Repo struct {
ID string // "ggerganov/whisper.cpp"
Revision string // "" means "main"
}
type Client struct {
BaseURL string // "https://huggingface.co", overridable in tests
HTTP *http.Client
}
var ErrNotCached = errors.New("file not cached and download not allowed")
// EnsureFile returns the local path of file inside dir, downloading it from repo
// when it is missing and allowDownload is true; ErrNotCached otherwise.
func (c *Client) EnsureFile(ctx context.Context, repo Repo, file, dir, label string, allowDownload bool) (string, error)ModelManager and TTSModelManager keep their types, constructors and public methods. Internally they drop baseURL/client for a *huggingface.Client plus a huggingface.Repo, call EnsureFile(..., cfg.AutoDownload), and turn ErrNotCached into their existing message. Repo is a value object: two repos with the same ID and revision are the same repo.
Not in scope: BinaryManager stays in internal/audio (it only swaps its progress reader import); no resume or retry (ponytail: no resume, add an HTTP Range retry in download.ToFile if multi-GB restarts annoy people); no hf CLI; no new config keys; no avatar code.
Acceptance Criteria
-
internal/platform/downloadholdsToFileandNewProgressReader, moved frominternal/audio/download.gowith their tests (download_test.go).internal/audio/download.gois deleted. -
internal/platform/huggingfaceholdsRepo,ClientandEnsureFile. It is the only non-test Go file in the repo containinghuggingface.coor/resolve/;huggingFaceWhisperBaseandqwen3TTSBaseare gone. -
internal/audio/model.goandttsmodel.gocontain no URL building, noos.Stat/MkdirAll/download sequence of their own, and still ownmodelFileName,ttsModelFiles,modelsDirand theauto_downloaderror text. -
binary.gousesdownload.NewProgressReader;BinaryManageris otherwise untouched. - No behaviour change: same URLs requested, same cache paths (
~/.infer/models/whisper,~/.infer/models/tts), same progress messages, same error strings includingspeech_to_text.auto_download is disabledandtext_to_speech.auto_download is disabled. The existingmodel_test.go,transcriber_test.goandsynthesizer_test.gopass with only their test-server wiring adapted (ahuggingface.ClientwithBaseURLset to thehttptestserver). -
huggingfacetests cover: file already cached (no request made), missing +allowDownload=falsereturnsErrNotCached, missing + allowed downloads todir/file, emptyRevisionresolves tomain, a non-200 leaves no file behind. - Dependency direction holds:
internal/platform/*does not importinternal/audio;internal/audioimports both new packages. New imports carry explicit aliases andtask lint:importspasses. -
task lintandtask testpass. PR body statesno docs ticket: internal-only refactor.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
refactor(platform): extract model-file downloads from internal/audio (#…
inference-gateway-releaser commentedon Sep 22, 2026
🎉 This issue has been resolved in version 0.205.2 🎉
The release is available on:
Your semantic-release bot 📦🚀