Merge branch 'feature/1.5-local-model' into 'main'

Fix: Service List AI Entry Error

See merge request apipark/APIPark!205
This commit is contained in:
刘健
2025-02-17 16:12:38 +08:00
5 changed files with 29 additions and 12 deletions
+4 -10
View File
@@ -83,15 +83,8 @@ func (i *imlLocalModelController) Deploy(ctx *gin.Context) {
"code": -1, "msg": "model is required", "success": "fail",
})
return
}
//err = i.initAILocalService(ctx, input.Model, input.Team)
//if err != nil {
// ctx.JSON(200, gin.H{
// "code": -1, "msg": err.Error(), "success": "fail",
// })
// return
//}
id := uuid.NewString()
p, err := i.module.Deploy(ctx, input.Model, id)
if err != nil {
@@ -105,10 +98,11 @@ func (i *imlLocalModelController) Deploy(ctx *gin.Context) {
go func() {
select {
case <-ctx.Writer.CloseNotify():
log.Info("client closed connection,close pipeline")
ai_provider_local.CancelPipeline(input.Model, id)
case <-done:
}
ai_provider_local.CancelPipeline(input.Model, id)
}()
var complete int64
var total int64
+3 -2
View File
@@ -9,6 +9,7 @@ type CancelDeploy struct {
}
type DeployInput struct {
Model string `json:"model"`
Team string `json:"team"`
Model string `json:"model"`
Service string `json:"service"`
Team string `json:"team"`
}
+9
View File
@@ -299,6 +299,15 @@ func (i *imlLocalModel) syncGateway(ctx context.Context, clusterId string, relea
func (i *imlLocalModel) Deploy(ctx context.Context, model string, session string) (*ai_provider_local.Pipeline, error) {
var p *ai_provider_local.Pipeline
err := i.transaction.Transaction(ctx, func(txCtx context.Context) error {
item, err := i.localModelCacheService.GetByTarget(ctx, ai_local.CacheTypeService, model)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
} else {
model = item.Model
}
info, err := i.localModelService.Get(ctx, model)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
+12
View File
@@ -201,6 +201,18 @@ type imlLocalModelCacheService struct {
store ai.ILocalModelCacheStore `autowired:""`
}
func (i *imlLocalModelCacheService) GetByTarget(ctx context.Context, typ CacheType, target string) (*LocalModelCache, error) {
item, err := i.store.First(ctx, map[string]interface{}{"target": target, "type": typ.Int()})
if err != nil {
return nil, err
}
return &LocalModelCache{
Model: item.Model,
Target: item.Target,
Type: CacheType(item.Type),
}, nil
}
func (i *imlLocalModelCacheService) List(ctx context.Context, model string, typ CacheType) ([]*LocalModelCache, error) {
list, err := i.store.List(ctx, map[string]interface{}{"model": model, "type": typ.Int()})
if err != nil {
+1
View File
@@ -34,6 +34,7 @@ type ILocalModelCacheService interface {
List(ctx context.Context, model string, typ CacheType) ([]*LocalModelCache, error)
Delete(ctx context.Context, model string) error
Save(ctx context.Context, model string, typ CacheType, target string) error
GetByTarget(ctx context.Context, typ CacheType, target string) (*LocalModelCache, error)
}
func init() {