diff --git a/ai-provider/local/executor.go b/ai-provider/local/executor.go index ae10a33c..b6648d23 100644 --- a/ai-provider/local/executor.go +++ b/ai-provider/local/executor.go @@ -288,7 +288,13 @@ func CancelPipeline(model string, id string) { func RemoveModel(model string) error { taskExecutor.CloseModelPipeline(model) - return client.Delete(context.Background(), &api.DeleteRequest{Model: model}) + err := client.Delete(context.Background(), &api.DeleteRequest{Model: model}) + if err != nil { + if err.Error() == fmt.Sprintf("model '%s' not found", model) { + return nil + } + } + return err } func ModelsInstalled() ([]Model, error) { diff --git a/controller/ai-local/iml.go b/controller/ai-local/iml.go index 40ddf818..a054973d 100644 --- a/controller/ai-local/iml.go +++ b/controller/ai-local/iml.go @@ -3,12 +3,15 @@ package ai_local import ( "context" "encoding/json" + "errors" "fmt" "io" "math" "net/http" "strings" + "gorm.io/gorm" + "github.com/APIParkLab/APIPark/module/router" "github.com/APIParkLab/APIPark/model/plugin_model" @@ -194,6 +197,14 @@ func (i *imlLocalModelController) DeployStart(ctx *gin.Context, input *ai_local_ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model string, teamID string) error { err := i.transaction.Transaction(ctx, func(ctx context.Context) error { + _, err := i.serviceModule.Get(ctx, model) + if err == nil { + return nil + } else { + if !errors.Is(err, gorm.ErrRecordNotFound) { + return err + } + } catalogueInfo, err := i.catalogueModule.DefaultCatalogue(ctx) if err != nil { return err diff --git a/module/ai-local/iml.go b/module/ai-local/iml.go index 51551201..e153dea4 100644 --- a/module/ai-local/iml.go +++ b/module/ai-local/iml.go @@ -210,6 +210,7 @@ func (i *imlLocalModel) CancelDeploy(ctx context.Context, model string) error { } func (i *imlLocalModel) RemoveModel(ctx context.Context, model string) error { + err := ai_provider_local.RemoveModel(model) if err != nil { return err