models

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package models manages ds4go's curated model catalog.

Index

Constants

View Source
const (

	// DefaultModelSymlink is the name of the active-model symlink in ModelsDir.
	DefaultModelSymlink = "ds4flash.gguf"

	// ConfigFileName is the ds4go configuration file name.
	ConfigFileName = "ds4go.json"

	// MTPAlias is the curated alias for the MTP companion model.
	MTPAlias = "mtp"

	// RecommendedModelAlias is the suggested default model for first-time users.
	RecommendedModelAlias = "q2-imatrix"
)

Variables

View Source
var ErrLocked = errors.New("lock already held by another process")

ErrLocked is returned by TryLock when another process already holds the lock.

Functions

func DefaultMTPPath added in v0.2.2

func DefaultMTPPath() string

DefaultMTPPath returns the path to the installed MTP companion model, or empty string if it is not present.

func DefaultModelPath

func DefaultModelPath() string

DefaultModelPath returns the configured default model path.

func GetLockHolder added in v0.4.0

func GetLockHolder(path string) (int, error)

GetLockHolder returns the PID of the process holding the lock on path. If the lock is not currently held, it returns 0, nil.

func GetProcessName added in v0.4.0

func GetProcessName(pid int) string

GetProcessName returns the executable name of the process with the given PID, or "unknown" if it cannot be determined.

Types

type Config

type Config struct {
	DefaultModel string           `json:"defaultModel"`
	DS4Dir       string           `json:"ds4Dir"`
	Models       map[string]Model `json:"models"`
}

Config is stored at $DS4_DIR/ds4go.json.

type FileLock added in v0.4.0

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

FileLock is an advisory, OS-level exclusive lock. The kernel releases it automatically when the holding process exits, so an interrupted process never leaves a stale lock behind.

func AcquireEngineRunLock added in v0.4.0

func AcquireEngineRunLock(modelPath string) (*FileLock, error)

AcquireEngineRunLock attempts to acquire the run lock file for a given model path. If the lock is already held by another process, it returns a descriptive error indicating the holding process PID and name.

func LockExclusive added in v0.4.0

func LockExclusive(path string) (*FileLock, error)

LockExclusive acquires an exclusive lock on path, creating the file if needed. Unlike TryLock, it waits for the existing holder to release it.

func TryLock added in v0.4.0

func TryLock(path string) (*FileLock, error)

TryLock acquires a non-blocking exclusive lock on path, creating the file if needed. It returns ErrLocked if another process holds the lock.

func (*FileLock) Close added in v0.4.0

func (l *FileLock) Close() error

Close releases the lock and closes the underlying file.

type Manager

type Manager struct {
	DS4Dir      string
	ModelsDir   string
	ConfigPath  string
	HTTPClient  *http.Client
	Out         io.Writer
	ProgressOut io.Writer
}

Manager manages the local ds4 model directory and config.

func NewManager

func NewManager() *Manager

NewManager returns a manager rooted at DS4_DIR or ~/.ds4.

func (*Manager) Delete

func (m *Manager) Delete(alias string) error

Delete removes a curated model's downloaded file and any partial download. If the deleted model was the default, the default is cleared.

func (*Manager) Download

func (m *Manager) Download(ctx context.Context, alias, token string) (Model, error)

Download downloads a curated model from Hugging Face with resume support.

func (*Manager) DownloadDryRun

func (m *Manager) DownloadDryRun(ctx context.Context, alias, token string) (Model, error)

DownloadDryRun resolves alias and reports what Download would fetch — the source URL, destination path, remote size/SHA256, and current local state — without downloading anything.

func (*Manager) List

func (m *Manager) List() ([]Model, Config, error)

List returns curated models annotated with installed/default state.

func (*Manager) LoadConfig

func (m *Manager) LoadConfig() (Config, error)

LoadConfig reads ds4go.json.

func (*Manager) SaveConfig

func (m *Manager) SaveConfig(cfg Config) error

SaveConfig writes ds4go.json.

func (*Manager) Set

func (m *Manager) Set(alias string) error

Set switches the default model and updates models/ds4flash.gguf.

type Model

type Model struct {
	Alias          string  `json:"alias"`
	GGUFPath       string  `json:"ggufPath"`
	FileName       string  `json:"fileName"`
	SizeGB         float64 `json:"sizeGB"`
	RecommendedRAM string  `json:"recommendedRAM"`
	SHA256         string  `json:"sha256,omitempty"`
	Imatrix        bool    `json:"imatrix"`
	Legacy         bool    `json:"legacy"`
	Optional       bool    `json:"optional"`
	Notes          string  `json:"notes,omitempty"`
	Installed      bool    `json:"installed"`
	Partial        bool    `json:"partial"`
	PartialBytes   int64   `json:"partialBytes,omitempty"`
	Default        bool    `json:"default"`
}

Model describes a curated ds4 GGUF model.

func Curated

func Curated() []Model

Curated returns a copy of the curated ds4 model catalog.

func Lookup added in v0.2.2

func Lookup(alias string) (Model, bool)

Lookup returns the curated model for alias, or false if unknown.

Jump to

Keyboard shortcuts

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