modelprovider

package
v0.1.1-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResetRegistry

func ResetRegistry()

ResetRegistry resets the singleton instance This should only be used in tests to ensure isolation between test cases

Types

type Provider

type Provider interface {
	// Name returns the human-readable name of the provider
	// Example: "huggingface", "modelscope", "civitai"
	Name() string

	// SupportsURL checks if this provider can handle the given model URL
	// This enables automatic provider detection based on full URL patterns (with domain)
	// Short-form URLs (owner/repo) require explicit provider specification via GetProviderByName
	SupportsURL(url string) bool

	// DownloadModel downloads a model from the provider and returns the local path
	// Parameters:
	//   - ctx: context for cancellation and timeout
	//   - modelURL: the URL or identifier of the model to download
	//   - destDir: the destination directory where the model should be downloaded
	// Returns:
	//   - string: the local path where the model was downloaded
	//   - error: any error that occurred during download
	DownloadModel(ctx context.Context, modelURL, destDir string) (string, error)

	// CheckAuth verifies that the user is authenticated with the provider
	// Returns an error if authentication is missing or invalid
	CheckAuth() error
}

Provider defines the interface that all model providers must implement. A provider is responsible for downloading models from a specific source (e.g., HuggingFace, ModelScope, Civitai, etc.)

type Registry

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

Registry manages all available model providers and provides functionality to select the appropriate provider for a given URL

func GetRegistry

func GetRegistry() *Registry

GetRegistry returns the singleton instance of the registry This is thread-safe and will only create the instance once

func (*Registry) GetProvider

func (r *Registry) GetProvider(modelURL string) (Provider, error)

GetProvider returns the appropriate provider for the given model URL It iterates through all registered providers and returns the first one that supports the URL. This only works for full URLs with domain names. For short-form URLs (owner/repo), use GetProviderByName with an explicit provider

func (*Registry) GetProviderByName

func (r *Registry) GetProviderByName(name string) (Provider, error)

GetProviderByName returns a specific provider by its name This is useful when you want to explicitly select a provider

func (*Registry) ListProviders

func (r *Registry) ListProviders() []string

ListProviders returns the names of all registered providers

func (*Registry) SelectProvider

func (r *Registry) SelectProvider(modelURL, providerName string) (Provider, error)

SelectProvider returns the appropriate provider based on the URL and explicit provider name If providerName is specified, it uses GetProviderByName for short-form URLs Otherwise, it uses GetProvider for auto-detection with full URLs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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