Files
cloudpods/pkg/llm/models/llm_container_driver.go
T
cwz_eikoh 897a6fc61f [OSPP]feature: Auto deploy llm and dify (#23282)
* feat(llm): add llm-create

* fix(llm): fix llm-create, add llm-list & llm-show

* fix(llm): format file names

* fear(llm): add exec stream

* fear(llm): init llm model cache

* fix(llm): move llm model cache to LocalImageCache

* feat(llm): auto clean model cache

* fix(llm): auto clean tmp model cache

* feat(dify): init dify-create

* fix(dify): change dify default registry

* feat: support create model with gguf file

* feat(llm): support more modelfile option for gguf file

* feat(dify): init user customize dify parameters

* feat: update llm as a service in climc

* fix: delete llm from region service

* feat: init llm service (with error)

* fix: resolve errors (task cant callback yet)

* feat: add PerformRequestHostActionByOtherService for container

* fix: make llm service usable

* feat: delete llm and dify after guest deleted

* feat(llm): add llm-image

* feat(llm): add llm-model

* feat: mv old llm to ollama

* feat(llm): init llm-batch-create(can not run)

* fix(llm): make llm-create usable

* fix(llm): add pull-model step

* feat(llm): add list and delete

* fix(llm): ollama pull official model don't rely on host & region's code any more

* feat(llm): add dify-model

* fix: remove llm's code in host & compute

* fix: remove remain code in compute

* feat(llm): Abstract out and reuse the llm_model logic

* feat(llm): abstract llm_base from llm

* fix(llm): make dify usable

* feat(llm): add sync_dify_images.sh

* fix(llm): format import

* feat(llm): support start & stop for llm and dify

* feat(llm): add model-update

* fix(llm): gendocgo
2025-10-24 13:29:31 +08:00

91 lines
2.8 KiB
Go

package models
import (
"context"
"sync"
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/apis/llm"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
)
type drivers struct {
drivers *sync.Map
}
func newDrivers() *drivers {
return &drivers{
drivers: &sync.Map{},
}
}
func (d *drivers) GetWithError(typ string) (interface{}, error) {
drv, ok := d.drivers.Load(typ)
if !ok {
return drv, httperrors.NewNotFoundError("app container driver %s not found", typ)
}
return drv, nil
}
func (d *drivers) Get(typ string) interface{} {
drv, err := d.GetWithError(typ)
if err != nil {
panic(err.Error())
}
return drv
}
func (d *drivers) Register(typ string, drv interface{}) {
d.drivers.Store(typ, drv)
}
func registerDriver[K ~string, D any](drvs *drivers, typ K, drv D) {
drvs.Register(string(typ), drv)
}
func getDriver[K ~string, D any](drvs *drivers, typ K) D {
return drvs.Get(string(typ)).(D)
}
func getDriverWithError[K ~string, D any](drvs *drivers, typ K) (D, error) {
drv, err := drvs.GetWithError(string(typ))
if err != nil {
return drv.(D), err
}
return drv.(D), nil
}
type ILLMContainerPullModel interface {
// PullModelByInstall(ctx context.Context, userCred mcclient.TokenCredential, llm *SLLM, modelName string, modelTag string) error
// PullModelByGgufFile(ctx context.Context, userCred mcclient.TokenCredential, llm *SLLM, ggufFileUrl string, model string) error
// DownloadGgufFile(ctx context.Context, userCred mcclient.TokenCredential, llm *SLLM, ggufFileUrl string, ggufFilePath string) error
// InstallGgufModel(ctx context.Context, userCred mcclient.TokenCredential, llm *SLLM, ggufFilePath string) error
GetManifests(ctx context.Context, userCred mcclient.TokenCredential, llm *SLLM, taskId string) error
AccessBlobsCache(ctx context.Context, userCred mcclient.TokenCredential, llm *SLLM, taskId string) error
CopyBlobs(ctx context.Context, userCred mcclient.TokenCredential, llm *SLLM) error
}
type ILLMContainerDriver interface {
GetType() llm.LLMContainerType
GetContainerSpec(ctx context.Context, llm *SLLM, image *SLLMImage, sku *SLLMModel, props []string, devices []computeapi.SIsolatedDevice, diskId string) *computeapi.PodContainerCreateInput
// ILLMContainerPullModel
}
var (
llmContainerDrivers = newDrivers()
)
func RegisterLLMContainerDriver(drv ILLMContainerDriver) {
registerDriver(llmContainerDrivers, drv.GetType(), drv)
}
func GetLLMContainerDriver(typ llm.LLMContainerType) ILLMContainerDriver {
return getDriver[llm.LLMContainerType, ILLMContainerDriver](llmContainerDrivers, typ)
}
func GetLLMContainerDriverWithError(typ llm.LLMContainerType) (ILLMContainerDriver, error) {
return getDriverWithError[llm.LLMContainerType, ILLMContainerDriver](llmContainerDrivers, typ)
}