model

package
v0.9.30 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectPipelineTag

func DetectPipelineTag(modelDir string) string

DetectPipelineTag reads config.json in modelDir and returns a local pipeline tag for routing. Sentence-transformers repositories are treated as embedding models even when the hub metadata was not persisted in older manifests.

func EnsureLocalModelFiles

func EnsureLocalModelFiles(modelDir string, m *LocalModel) (bool, error)

func EnsureModelDir

func EnsureModelDir(baseDir, namespace, name string) error

EnsureModelDir creates the directory for a model if it doesn't exist.

func FindMMProj

func FindMMProj(modelDir string) string

FindMMProj looks for a multimodal projector GGUF file (mmproj) in the model directory.

func InferenceModelID

func InferenceModelID(lm *LocalModel) string

InferenceModelID returns the public model identifier used for local inference APIs.

func IsASRArchitecture

func IsASRArchitecture(architecture string) bool

IsASRArchitecture reports whether the HuggingFace architecture is an automatic speech recognition model.

func IsASRModelFamily

func IsASRModelFamily(name string) bool

IsASRModelFamily reports whether a model id/name belongs to a known ASR family served by the Python ASR runtime.

func IsEmbeddingArchitecture

func IsEmbeddingArchitecture(architecture string) bool

IsEmbeddingArchitecture reports whether the HuggingFace architecture is treated as a local embedding model by csghub-lite.

func IsPythonEmbeddingArchitecture added in v0.9.8

func IsPythonEmbeddingArchitecture(architecture string) bool

IsPythonEmbeddingArchitecture reports whether the HuggingFace architecture is supported by csghub-lite's Python embedding runtime.

func IsVisionArchitecture

func IsVisionArchitecture(architecture string) bool

IsVisionArchitecture reports whether the HuggingFace architecture is a supported multimodal vision-language model.

func ListModelsInNamespace

func ListModelsInNamespace(baseDir, namespace string) ([]string, error)

ListModelsInNamespace returns all model directories under a namespace.

func ListNamespaces

func ListNamespaces(baseDir string) ([]string, error)

ListNamespaces returns all namespace directories under the model base dir.

func ManifestPath

func ManifestPath(baseDir, namespace, name string) string

ManifestPath returns the path to the manifest file for a model.

func ModelDir

func ModelDir(baseDir, namespace, name string) string

ModelDir returns the directory for a specific model.

func PublicModelIDs

func PublicModelIDs(models []*LocalModel) map[string]string

PublicModelIDs returns stable short model IDs keyed by each model's full namespace/name ID. When names collide, the first downloaded model keeps the bare name and later colliding models get a stable hash suffix.

func RemoveModelDir

func RemoveModelDir(baseDir, namespace, name string) error

RemoveModelDir removes the directory for a model.

func SaveManifest

func SaveManifest(baseDir string, m *LocalModel) error

SaveManifest writes a model manifest to disk.

func SaveManifestInDir

func SaveManifestInDir(modelDir string, m *LocalModel) error

SaveManifestInDir writes a manifest to a prepared model directory before it is installed.

Types

type Format

type Format string
const (
	FormatGGUF        Format = "gguf"
	FormatSafeTensors Format = "safetensors"
	FormatPyTorch     Format = "pytorch"
	FormatUnknown     Format = "unknown"
)

func DetectFormat

func DetectFormat(files []string) Format

DetectFormat guesses the model format from the file names.

func FindModelFile

func FindModelFile(modelDir string) (string, Format, error)

FindModelFile returns the primary model file (GGUF or SafeTensors).

type ImportOptions

type ImportOptions struct {
	ModelID   string
	Source    string
	Kind      ImportSourceKind
	Overwrite bool
}

type ImportSourceKind

type ImportSourceKind string
const (
	ImportSourceDirectory ImportSourceKind = "directory"
	ImportSourceArchive   ImportSourceKind = "archive"
)

type LocalModel

type LocalModel struct {
	Namespace    string           `json:"namespace"`
	Name         string           `json:"name"`
	Format       Format           `json:"format"`
	Size         int64            `json:"size"`
	Files        []string         `json:"files"`
	FileEntries  []LocalModelFile `json:"file_entries,omitempty"`
	DownloadedAt time.Time        `json:"downloaded_at"`
	Origin       LocalModelOrigin `json:"origin,omitempty"`
	Description  string           `json:"description,omitempty"`
	License      string           `json:"license,omitempty"`
	PipelineTag  string           `json:"pipeline_tag,omitempty"`
}

func LoadManifest

func LoadManifest(baseDir, namespace, name string) (*LocalModel, error)

LoadManifest reads a model manifest from disk.

func (*LocalModel) FullName

func (m *LocalModel) FullName() string

type LocalModelFile

type LocalModelFile struct {
	Path   string `json:"path"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256,omitempty"`
	LFS    bool   `json:"lfs,omitempty"`
}

type LocalModelOrigin

type LocalModelOrigin string
const (
	LocalModelOriginUpload      LocalModelOrigin = "upload"
	LocalModelOriginMarketplace LocalModelOrigin = "marketplace"
)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(cfg *config.Config) *Manager

func (*Manager) Client

func (m *Manager) Client() *csghub.Client

Client returns the underlying CSGHub client.

func (*Manager) Exists

func (m *Manager) Exists(modelID string) bool

Exists checks if a model is downloaded locally.

func (*Manager) Get

func (m *Manager) Get(modelID string) (*LocalModel, error)

Get returns a locally downloaded model by ID.

func (*Manager) GetWithFileEntries

func (m *Manager) GetWithFileEntries(modelID string) (*LocalModel, error)

GetWithFileEntries returns a local model with file-level metadata filled in.

func (*Manager) Import

func (m *Manager) Import(opts ImportOptions) (*LocalModel, error)

Import copies a prepared local source into the managed model store and writes a fresh manifest.

func (*Manager) ImportPreparedDirectory

func (m *Manager) ImportPreparedDirectory(opts ImportOptions) (*LocalModel, error)

ImportPreparedDirectory installs an already-staged directory into the managed model store without copying it through an additional prepared directory first.

func (*Manager) List

func (m *Manager) List() ([]*LocalModel, error)

List returns all locally downloaded models.

func (*Manager) ModelPath

func (m *Manager) ModelPath(modelID string) (string, error)

ModelPath returns the directory path for a model.

func (*Manager) PublicModelID

func (m *Manager) PublicModelID(modelID string) (string, error)

PublicModelID resolves a local model ID and returns its public inference ID.

func (*Manager) Pull

func (m *Manager) Pull(ctx context.Context, modelID string, quants []string, progress csghub.SnapshotProgressFunc) (*LocalModel, error)

Pull downloads a model from CSGHub. quants selects GGUF weight variants when the repository exposes multiple quantizations (for example Q4_K_M or Q8_0). Empty quants keeps the default behavior (highest-precision GGUF variant). Non-GGUF models ignore quants.

func (*Manager) Remove

func (m *Manager) Remove(modelID string) error

Remove deletes a locally downloaded model.

func (*Manager) ResolveLocalModel

func (m *Manager) ResolveLocalModel(modelID string) (*LocalModel, error)

ResolveLocalModel resolves a downloaded local model by full ID (namespace/name) or by short name (name only).

func (*Manager) ResolveLocalModelID

func (m *Manager) ResolveLocalModelID(modelID string) (string, error)

ResolveLocalModelID returns the on-disk namespace/name identifier for a local model.

Jump to

Keyboard shortcuts

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