Documentation
¶
Index ¶
- func ComputeCompositeHash(files []HashManifestFile) string
- func DownloadModel(ctx context.Context, files []ModelFile, destDir string) error
- func DownloadModelAndSaveManifest(ctx context.Context, modelID string, files []ModelFile, destDir string) error
- func HuggingFaceModelSize(files []ModelFile) int64
- func SaveHashManifest(modelID, destDir string, files []ModelFile) error
- type CatalogModel
- type CatalogResponse
- type HFLFS
- type HFModelInfo
- type HFSibling
- type HashManifest
- type HashManifestFile
- type ModelFile
- type ModelFilesResponse
- type VerifyResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeCompositeHash ¶
func ComputeCompositeHash(files []HashManifestFile) string
ComputeCompositeHash computes a deterministic composite hash from per-file hashes. Algorithm: sort filenames alphabetically, concatenate "filename:hash\n" strings, SHA256 the result. This must match the server-side algorithm in swan-inference.
func DownloadModel ¶
DownloadModel downloads all model files to destDir. It skips files that already exist with the correct size and hash.
func DownloadModelAndSaveManifest ¶
func DownloadModelAndSaveManifest(ctx context.Context, modelID string, files []ModelFile, destDir string) error
DownloadModelAndSaveManifest downloads a model and saves the hash manifest. This is the recommended entry point for model downloads.
func HuggingFaceModelSize ¶
HuggingFaceModelSize returns the total size of all files.
func SaveHashManifest ¶
SaveHashManifest saves a hash manifest for a downloaded model. Should be called after DownloadModel() succeeds.
Types ¶
type CatalogModel ¶
type CatalogModel struct {
ModelID string `json:"model_id"`
Name string `json:"name"`
Category string `json:"category"`
FileCount int `json:"file_count"`
TotalSizeBytes int64 `json:"total_size_bytes"`
WeightSourceURL string `json:"weight_source_url,omitempty"`
}
CatalogModel represents a model available in the Swan Model Repository.
type CatalogResponse ¶
type CatalogResponse struct {
Models []CatalogModel `json:"models"`
Total int `json:"total"`
}
CatalogResponse is the response from GET /api/v1/models/catalog.
func FetchCatalog ¶
func FetchCatalog(serviceURL string) (*CatalogResponse, error)
FetchCatalog calls the swan-inference API to get the list of available models.
type HFModelInfo ¶
type HFModelInfo struct {
Siblings []HFSibling `json:"siblings"`
}
HFModelInfo is the response from the HuggingFace model API.
type HFSibling ¶
type HFSibling struct {
RFilename string `json:"rfilename"`
Size int64 `json:"size"`
LFS *HFLFS `json:"lfs,omitempty"`
}
HFSibling represents a file in a HuggingFace model repository.
type HashManifest ¶
type HashManifest struct {
ModelID string `json:"model_id"`
CompositeHash string `json:"composite_hash"`
Algorithm string `json:"algorithm"`
Files []HashManifestFile `json:"files"`
CreatedAt string `json:"created_at"`
}
HashManifest stores per-file hashes and a composite hash for model weight verification. Saved as .swan-hash-manifest.json in the model directory.
func LoadHashManifest ¶
func LoadHashManifest(destDir string) (*HashManifest, error)
LoadHashManifest loads a hash manifest from a model directory. Returns nil, nil if the manifest does not exist.
type HashManifestFile ¶
type HashManifestFile struct {
Filename string `json:"filename"`
Hash string `json:"hash"`
SizeBytes int64 `json:"size_bytes"`
}
HashManifestFile describes a single file's hash in the manifest
type ModelFile ¶
type ModelFile struct {
Filename string `json:"filename"`
Hash string `json:"hash"`
Algorithm string `json:"algorithm"`
SizeBytes int64 `json:"size_bytes"`
URL string `json:"url"`
}
ModelFile represents a single file in a model's weight repository.
func FetchHuggingFaceFiles ¶
FetchHuggingFaceFiles fetches the file list for a model from HuggingFace.
type ModelFilesResponse ¶
type ModelFilesResponse struct {
ModelID string `json:"model_id"`
Files []ModelFile `json:"files"`
TotalSizeBytes int64 `json:"total_size_bytes"`
FileCount int `json:"file_count"`
}
ModelFilesResponse is the response from GET /api/v1/models/:model_id/files.
func FetchModelFiles ¶
func FetchModelFiles(serviceURL, modelID string) (*ModelFilesResponse, error)
FetchModelFiles calls the swan-inference API to get the file manifest for a model.
type VerifyResult ¶
type VerifyResult struct {
Filename string
Status string // "pass", "fail", "missing"
Expected string
Actual string
}
VerifyResult describes the result of verifying a single file.
func VerifyModel ¶
func VerifyModel(files []ModelFile, destDir string) []VerifyResult
VerifyModel checks each local file against expected hashes.