model

package
v0.9.66 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 26 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 in the model directory.

func FindMMProjFiles added in v0.9.37

func FindMMProjFiles(modelDir string) ([]string, error)

FindMMProjFiles returns multimodal projector GGUF files ordered with conventionally named mmproj files first, then metadata-detected projectors.

func FindMTPFiles added in v0.9.37

func FindMTPFiles(modelDir string) ([]string, error)

FindMTPFiles returns Multi-Token Prediction companion GGUF files.

func FindWeightGGUFRelPaths added in v0.9.37

func FindWeightGGUFRelPaths(modelDir string) ([]string, error)

FindWeightGGUFRelPaths returns main-model GGUF paths while excluding filename- and metadata-identified companion modules.

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 MaxModelLen added in v0.9.31

func MaxModelLen(modelDir string, format Format) (int64, error)

MaxModelLen returns the model's native maximum context length. GGUF models carry this value in their metadata header; SafeTensors models use the Hugging Face config.json stored alongside the weights.

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 storage ID. OpenCSG and imported models preserve short IDs for compatibility; external registry models use source/namespace/name and therefore do not collide across registries.

func RegistryModelDir added in v0.9.53

func RegistryModelDir(baseDir, artifactSource, namespace, name string) string

RegistryModelDir keeps historical OpenCSG/import paths stable while namespacing external registries so identical repository IDs can coexist.

func RemoveModelDir

func RemoveModelDir(baseDir, namespace, name string) error

RemoveModelDir removes the directory for a model.

func RemoveRegistryModelDir added in v0.9.53

func RemoveRegistryModelDir(baseDir, artifactSource, namespace, name string) error

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"`
	ArtifactSource    string           `json:"artifact_source,omitempty"`
	Repository        string           `json:"repository,omitempty"`
	RequestedRevision string           `json:"requested_revision,omitempty"`
	ResolvedRevision  string           `json:"resolved_revision,omitempty"`
}

func LoadManifest

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

LoadManifest reads a model manifest from disk.

func LoadManifestInDir added in v0.9.53

func LoadManifestInDir(modelDir string) (*LocalModel, error)

LoadManifestInDir reads a manifest from an already resolved model directory.

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) PullFrom added in v0.9.53

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

PullFrom downloads a model from an artifact registry. Empty source preserves the historical OpenCSG behavior.

func (*Manager) Remove

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

Remove deletes a locally downloaded model.

func (*Manager) RemovePartial added in v0.9.53

func (m *Manager) RemovePartial(modelID, sourceValue string) (string, error)

RemovePartial removes an incomplete registry download without touching an installed model. It returns the removed directory for user-facing diagnostics.

func (*Manager) ResolveLocalModel

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

ResolveLocalModel resolves a downloaded local model by storage ID ([source/]namespace/name) or by its public inference ID.

func (*Manager) ResolveLocalModelID

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

ResolveLocalModelID returns the on-disk [source/]namespace/name identifier.

Jump to

Keyboard shortcuts

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