Documentation
¶
Index ¶
- type BuildFormat
- type BuildOption
- type Builder
- func (b *Builder) Build(ctx context.Context, target Target, pw io.Writer) error
- func (b *Builder) HasOnlyConfigChanges() bool
- func (b *Builder) Model() types.ModelArtifact
- func (b *Builder) WithChatTemplateFile(path string) (*Builder, error)
- func (b *Builder) WithConfigArchive(path string) (*Builder, error)
- func (b *Builder) WithContextSize(size int32) (*Builder, error)
- func (b *Builder) WithFileLayer(absPath, relPath string) (*Builder, error)
- func (b *Builder) WithLicense(path string) (*Builder, error)
- func (b *Builder) WithMultimodalProjector(path string) (*Builder, error)
- type DirectoryOption
- type DirectoryOptions
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildFormat ¶ added in v1.1.36
type BuildFormat string
BuildFormat specifies the output artifact format.
const ( // BuildFormatDocker produces Docker-proprietary format artifacts // (application/vnd.docker.ai.* media types). This is the default. BuildFormatDocker BuildFormat = "docker" // BuildFormatCNCF produces CNCF ModelPack format artifacts // (application/vnd.cncf.model.* media types). BuildFormatCNCF BuildFormat = "cncf" )
type BuildOption ¶ added in v1.0.18
type BuildOption func(*buildOptions)
BuildOption configures the behavior of FromPath and FromPaths.
func WithCreated ¶ added in v1.0.18
func WithCreated(t time.Time) BuildOption
WithCreated sets a specific creation timestamp for the model artifact. When not set, the current time (time.Now()) is used. This is useful for producing deterministic OCI digests when the same model content should always yield the same artifact regardless of when it was built.
func WithFormat ¶ added in v1.1.36
func WithFormat(f BuildFormat) BuildOption
WithFormat sets the output artifact format. Defaults to BuildFormatDocker.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds a model artifact.
func FromDirectory ¶ added in v1.0.14
func FromDirectory(dirPath string, opts ...DirectoryOption) (*Builder, error)
FromDirectory creates a Builder from a directory containing model files. It recursively scans the directory and adds each non-hidden file as a separate layer. Each layer's filepath annotation preserves the relative path from the directory root.
The directory structure is fully preserved, enabling support for nested HuggingFace models like Qwen3-TTS that have subdirectories (text_encoder/, vae/, etc.).
Example directory structure:
model_dir/
config.json -> layer with annotation "config.json"
model.safetensors -> layer with annotation "model.safetensors"
text_encoder/
config.json -> layer with annotation "text_encoder/config.json"
model.safetensors -> layer with annotation "text_encoder/model.safetensors"
Example with exclusions:
builder.FromDirectory(dirPath, builder.WithExclusions(".git", "__pycache__", "*.log"))
func FromModel ¶
func FromModel(mdl types.ModelArtifact, opts ...BuildOption) (*Builder, error)
FromModel returns a *Builder that builds model artifacts from an existing model artifact. When WithFormat is provided, the output uses that format. When no format is specified, the builder inherits the source model's format (auto-detecting CNCF ModelPack via the config). This prevents accidentally producing inconsistent artifacts when repackaging a CNCF model without an explicit --format flag.
func FromPath ¶ added in v1.0.11
func FromPath(path string, opts ...BuildOption) (*Builder, error)
FromPath returns a *Builder that builds model artifacts from a file path. It auto-detects the model format (GGUF or Safetensors) and discovers any shards. This is the preferred entry point for creating models from local files.
func FromPaths ¶ added in v1.0.11
func FromPaths(paths []string, opts ...BuildOption) (*Builder, error)
FromPaths returns a *Builder that builds model artifacts from multiple file paths. All paths must be of the same format. Use this when you already have the list of files.
func (*Builder) Build ¶
Build finalizes the artifact and writes it to the given target, reporting progress to the given writer
func (*Builder) HasOnlyConfigChanges ¶
HasOnlyConfigChanges returns true if the builder was created from an existing model and only configuration changes were made (no layers added or removed). This is useful for determining if lightweight repackaging optimizations can be used.
func (*Builder) Model ¶
func (b *Builder) Model() types.ModelArtifact
Model returns the underlying model artifact
func (*Builder) WithChatTemplateFile ¶
WithChatTemplateFile adds a Jinja chat template file to the artifact, taking precedence over any template embedded in the GGUF file.
func (*Builder) WithConfigArchive ¶
WithConfigArchive adds a config archive (tar) file to the artifact.
func (*Builder) WithContextSize ¶
WithContextSize sets the context size for the model artifact. Returns an error when the output format is CNCF (context size is not defined in the CNCF ModelPack specification).
func (*Builder) WithFileLayer ¶ added in v1.0.14
WithFileLayer adds an individual file layer with a relative path annotation. This is useful for adding files that should be extracted to a specific path.
func (*Builder) WithLicense ¶
WithLicense adds a license file to the artifact.
type DirectoryOption ¶ added in v1.0.14
type DirectoryOption func(*DirectoryOptions)
DirectoryOption is a functional option for configuring FromDirectory.
func WithCreatedTime ¶ added in v1.0.18
func WithCreatedTime(t time.Time) DirectoryOption
WithCreatedTime sets a specific creation timestamp for the model artifact built from a directory. When not set, the current time (time.Now()) is used. This is useful for producing deterministic OCI digests when the same directory content should always yield the same artifact regardless of when it was built.
func WithExclusions ¶ added in v1.0.14
func WithExclusions(patterns ...string) DirectoryOption
WithExclusions specifies patterns to exclude from packaging. Patterns can be directory names, file names, glob patterns, or specific paths.
Examples:
WithExclusions(".git", "__pycache__") // Exclude directories
WithExclusions("README.md", "CHANGELOG.md") // Exclude specific files
WithExclusions("*.log", "*.tmp") // Exclude by pattern
WithExclusions("logs/", "cache/") // Exclude directories (trailing slash)
func WithOutputFormat ¶ added in v1.1.36
func WithOutputFormat(f BuildFormat) DirectoryOption
WithOutputFormat sets the output artifact format for the directory builder. Defaults to BuildFormatDocker if not specified. This is the DirectoryOption equivalent of WithFormat (BuildOption).
type DirectoryOptions ¶ added in v1.0.14
type DirectoryOptions struct {
// Exclusions is a list of patterns to exclude from packaging.
// Patterns can be:
// - Directory names (e.g., ".git", "__pycache__") - excludes the entire directory
// - File names (e.g., "README.md") - excludes files with this exact name
// - Glob patterns (e.g., "*.log", "*.tmp") - excludes files matching the pattern
// - Paths with slashes (e.g., "logs/debug.log") - excludes specific paths
Exclusions []string
// Created is an optional creation timestamp for the model artifact.
// When set, it overrides the default behavior of using time.Now().
// This is useful for producing deterministic OCI digests.
Created *time.Time
// Format is the output artifact format. Defaults to BuildFormatDocker.
Format BuildFormat
}
DirectoryOptions configures the behavior of FromDirectory.