store

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConcurrentUpdate is returned when there is a concurrent update.
	ErrConcurrentUpdate = fmt.Errorf("store: concurrent update")
)

Functions

func DeleteBaseModelInTransaction added in v1.10.0

func DeleteBaseModelInTransaction(tx *gorm.DB, modelID, tenantID string) error

DeleteBaseModelInTransaction deletes a base model by model ID and tenant ID.

func DeleteHFModelRepoInTransactionByModelID added in v1.14.0

func DeleteHFModelRepoInTransactionByModelID(tx *gorm.DB, modelID, tenantID string) error

DeleteHFModelRepoInTransactionByModelID deletes a model repo.

func UnmarshalModelFormats

func UnmarshalModelFormats(b []byte) ([]v1.ModelFormat, error)

UnmarshalModelFormats unmarshals model formats.

Types

type BaseModel

type BaseModel struct {
	gorm.Model

	TenantID string `gorm:"uniqueIndex:idx_base_model_model_id_tenant_id"`

	ModelID string `gorm:"uniqueIndex:idx_base_model_model_id_tenant_id"`
	Path    string

	Formats []byte

	// GGUFModelPath is the path to the GGUF model.
	GGUFModelPath string

	SourceRepository v1.SourceRepository
	LoadingStatus    v1.ModelLoadingStatus

	LoadingFailureReason string
}

BaseModel represents a base model.

type HFModelRepo added in v1.4.0

type HFModelRepo struct {
	gorm.Model

	Name     string `gorm:"uniqueIndex:idx_hf_model_repo_name_tenant_id"`
	ModelID  string `gorm:"uniqueIndex:idx_hf_model_repo_model_id_tenant_id"`
	TenantID string `gorm:"uniqueIndex:idx_hf_model_repo_name_tenant_id;uniqueIndex:idx_hf_model_repo_model_id_tenant_id"`
}

HFModelRepo represents a HuggingFace model repository where models are downloaded from. This is used to track a HuggingFace repo that has one-to-many mapping to base models.

The record is created when the download completes.

type Model

type Model struct {
	gorm.Model

	TenantID string `gorm:"uniqueIndex:idx_model_model_id_tenant_id"`
	ModelID  string `gorm:"uniqueIndex:idx_model_model_id_tenant_id"`

	OrganizationID string
	ProjectID      string `gorm:"index"`

	Path        string
	IsPublished bool

	BaseModelID  string `gorm:"index"`
	Adapter      v1.AdapterType
	Quantization v1.QuantizationType

	LoadingStatus        v1.ModelLoadingStatus
	LoadingFailureReason string

	SourceRepository  v1.SourceRepository
	ModelFileLocation string
}

Model represents a model.

type ModelSpec

type ModelSpec struct {
	ModelID           string
	TenantID          string
	OrganizationID    string
	ProjectID         string
	Path              string
	IsPublished       bool
	BaseModelID       string
	Adapter           v1.AdapterType
	Quantization      v1.QuantizationType
	LoadingStatus     v1.ModelLoadingStatus
	SourceRepository  v1.SourceRepository
	ModelFileLocation string
}

ModelSpec represents a model spec that is passed to CreateModel.

type S

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

S represents the data store.

func New

func New(db *gorm.DB) *S

New creates a new store instance.

func NewTest

func NewTest(t *testing.T) (*S, func())

NewTest returns a new test store.

func (*S) AutoMigrate

func (s *S) AutoMigrate() error

AutoMigrate sets up the auto-migration task of the database.

func (*S) CountBaseModels added in v1.11.0

func (s *S) CountBaseModels(tenantID string) (int64, error)

CountBaseModels counts the total number of base models.

func (*S) CountModelsByProjectID added in v1.11.0

func (s *S) CountModelsByProjectID(projectID string, onlyPublished bool) (int64, error)

CountModelsByProjectID counts the total number of models by project ID.

func (*S) CreateBaseModel

func (s *S) CreateBaseModel(
	modelID string,
	path string,
	formats []v1.ModelFormat,
	ggufModelPath string,
	sourceRepository v1.SourceRepository,
	tenantID string,
) (*BaseModel, error)

CreateBaseModel creates a model.

func (*S) CreateBaseModelWithLoadingRequested added in v1.10.0

func (s *S) CreateBaseModelWithLoadingRequested(
	modelID string,
	sourceRepository v1.SourceRepository,
	tenantID string,
) (*BaseModel, error)

CreateBaseModelWithLoadingRequested creates a model with the requested loading status.

func (*S) CreateHFModelRepo added in v1.4.0

func (s *S) CreateHFModelRepo(
	name string,
	modelID string,
	tenantID string,
) (*HFModelRepo, error)

CreateHFModelRepo creates a model repo.

func (*S) CreateModel

func (s *S) CreateModel(spec ModelSpec) (*Model, error)

CreateModel creates a model.

func (*S) CreateStorageConfig

func (s *S) CreateStorageConfig(tenantID, pathPrefix string) (*StorageConfig, error)

CreateStorageConfig creates a storage configuration.

func (*S) DeleteBaseModel added in v1.9.0

func (s *S) DeleteBaseModel(modelID, tenantID string) error

DeleteBaseModel deletes a base model by model ID and tenant ID.

func (*S) DeleteModel

func (s *S) DeleteModel(modelID, tenantID string) error

DeleteModel deletes a model by model ID and tenant ID.

func (*S) GetBaseModel

func (s *S) GetBaseModel(modelID, tenantID string) (*BaseModel, error)

GetBaseModel returns a base model by model ID and tenant ID.

func (*S) GetHFModelRepo added in v1.4.0

func (s *S) GetHFModelRepo(name, tenantID string) (*HFModelRepo, error)

GetHFModelRepo returns a repo by the repo namen and tenant ID.

func (*S) GetModelByModelIDAndTenantID added in v1.14.0

func (s *S) GetModelByModelIDAndTenantID(modelID, tenantID string) (*Model, error)

GetModelByModelIDAndTenantID returns a model by model ID and tenant ID.

func (*S) GetPublishedModelByModelIDAndTenantID

func (s *S) GetPublishedModelByModelIDAndTenantID(modelID, tenantID string) (*Model, error)

GetPublishedModelByModelIDAndTenantID returns a published model by model ID and tenant ID.

func (*S) GetStorageConfig

func (s *S) GetStorageConfig(tenantID string) (*StorageConfig, error)

GetStorageConfig returns a storage configuration by tenant ID.

func (*S) ListBaseModels

func (s *S) ListBaseModels(tenantID string) ([]*BaseModel, error)

ListBaseModels returns all base models for a tenant.

func (*S) ListBaseModelsWithPagination added in v1.11.0

func (s *S) ListBaseModelsWithPagination(tenantID string, afterModelID string, limit int, includeLoadingModels bool) ([]*BaseModel, bool, error)

ListBaseModelsWithPagination finds base models with pagination. Models are returned with an ascending order of model IDs.

func (*S) ListHFModelRepos added in v1.4.0

func (s *S) ListHFModelRepos(tenantID string) ([]*HFModelRepo, error)

ListHFModelRepos returns all HuggingFace model repos for a tenant.

func (*S) ListModelsByProjectIDWithPagination added in v1.11.0

func (s *S) ListModelsByProjectIDWithPagination(
	projectID string,
	onlyPublished bool,
	afterModelID string,
	limit int,
	includeLoadingModels bool,
) ([]*Model, bool, error)

ListModelsByProjectIDWithPagination finds models with pagination. Models are returned with an ascending order of ID.

func (*S) ListUnloadedBaseModels added in v1.10.0

func (s *S) ListUnloadedBaseModels(tenantID string) ([]*BaseModel, error)

ListUnloadedBaseModels returns all unloaded base models with the requested loading status.

func (*S) ListUnloadedModels added in v1.14.0

func (s *S) ListUnloadedModels(tenantID string) ([]*Model, error)

ListUnloadedModels returns all unloaded base models with the requested loading status.

func (*S) Transaction added in v1.10.0

func (s *S) Transaction(f func(*gorm.DB) error) error

Transaction runs a given function in a transaction.

func (*S) UpdateBaseModelToFailedStatus added in v1.10.0

func (s *S) UpdateBaseModelToFailedStatus(
	modelID string,
	tenantID string,
	failureReason string,
) error

UpdateBaseModelToFailedStatus updates the loading status to FAILED and updates other relevant information.

func (*S) UpdateBaseModelToLoadingStatus added in v1.10.0

func (s *S) UpdateBaseModelToLoadingStatus(modelID string, tenantID string) error

UpdateBaseModelToLoadingStatus updates the loading status to LOADING.

func (*S) UpdateBaseModelToSucceededStatus added in v1.10.0

func (s *S) UpdateBaseModelToSucceededStatus(
	modelID string,
	tenantID string,
	path string,
	formats []v1.ModelFormat,
	ggufModelPath string,
) error

UpdateBaseModelToSucceededStatus updates the loading status to SUCCEEDED and updates other relevant information.

func (*S) UpdateModelPublishingStatus added in v1.14.0

func (s *S) UpdateModelPublishingStatus(modelID string, tenantID string, isPublished bool, loadingStatus v1.ModelLoadingStatus) error

UpdateModelPublishingStatus updates the publishing status of a model.

func (*S) UpdateModelToFailedStatus added in v1.14.0

func (s *S) UpdateModelToFailedStatus(modelID string, tenantID string, failureReason string) error

UpdateModelToFailedStatus updates the loading status to FAILED and updates other relevant information.

func (*S) UpdateModelToLoadingStatus added in v1.14.0

func (s *S) UpdateModelToLoadingStatus(modelID string, tenantID string) error

UpdateModelToLoadingStatus updates the loading status to LOADING.

func (*S) UpdateModelToSucceededStatus added in v1.14.0

func (s *S) UpdateModelToSucceededStatus(modelID string, tenantID string) error

UpdateModelToSucceededStatus updates the loading status to SUCCEEDED and updates other relevant information.

type StorageConfig

type StorageConfig struct {
	gorm.Model

	TenantID string `gorm:"uniqueIndex"`

	// PathPrefix is the prefix of the S3 path for storing models.
	PathPrefix string
}

StorageConfig represents a storage configuration for a tenant.

Jump to

Keyboard shortcuts

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