models

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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

func DownloadModel(ctx context.Context, files []ModelFile, destDir string) error

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

func HuggingFaceModelSize(files []ModelFile) int64

HuggingFaceModelSize returns the total size of all files.

func SaveHashManifest

func SaveHashManifest(modelID, destDir string, files []ModelFile) error

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 HFLFS

type HFLFS struct {
	SHA256 string `json:"sha256"`
	Size   int64  `json:"size"`
}

HFLFS contains LFS metadata for a file.

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

func FetchHuggingFaceFiles(modelID string) ([]ModelFile, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL