updated imageinference logics

Former-commit-id: 99ca94792385319288589344217693282e5d3eff
This commit is contained in:
tzwang 2024-08-30 09:47:46 +08:00
parent ef72b1014f
commit 5eda8232b1
4 changed files with 32 additions and 9 deletions

View File

@ -46,11 +46,14 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere
if err != nil { if err != nil {
return nil, err return nil, err
} }
if instance == nil {
return nil, errors.New("instance is empty ")
}
instanceList = append(instanceList, instance) instanceList = append(instanceList, instance)
} }
if len(instanceList) == 0 { if len(instanceList) == 0 {
return nil, errors.New("instances are empty") return nil, errors.New("instanceList are empty")
} }
// process uploaded images // process uploaded images
@ -110,7 +113,7 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere
} }
// set strategy // set strategy
if opt.Strategy != "" { if opt.Strategy == "" {
return nil, errors.New("strategy is empty") return nil, errors.New("strategy is empty")
} }

View File

@ -413,23 +413,23 @@ func (s *AiStorage) UpdateInferDeployInstance(instance *models.AiInferDeployInst
} }
func (s *AiStorage) GetInferDeployInstanceById(id int64) (*models.AiInferDeployInstance, error) { func (s *AiStorage) GetInferDeployInstanceById(id int64) (*models.AiInferDeployInstance, error) {
var deployIns models.AiInferDeployInstance var deployIns *models.AiInferDeployInstance
tx := s.DbEngin.Raw("select * from ai_infer_deploy_instance where `id` = ?", id).Scan(&deployIns) tx := s.DbEngin.Raw("select * from ai_infer_deploy_instance where `id` = ?", id).Scan(&deployIns)
if tx.Error != nil { if tx.Error != nil {
logx.Errorf(tx.Error.Error()) logx.Errorf(tx.Error.Error())
return nil, tx.Error return nil, tx.Error
} }
return &deployIns, nil return deployIns, nil
} }
func (s *AiStorage) GetDeployTaskById(id int64) (*models.AiDeployInstanceTask, error) { func (s *AiStorage) GetDeployTaskById(id int64) (*models.AiDeployInstanceTask, error) {
var task models.AiDeployInstanceTask var task *models.AiDeployInstanceTask
tx := s.DbEngin.Raw("select * from ai_deploy_instance_task where `id` = ?", id).Scan(&task) tx := s.DbEngin.Raw("select * from ai_deploy_instance_task where `id` = ?", id).Scan(&task)
if tx.Error != nil { if tx.Error != nil {
logx.Errorf(tx.Error.Error()) logx.Errorf(tx.Error.Error())
return nil, tx.Error return nil, tx.Error
} }
return &task, nil return task, nil
} }
func (s *AiStorage) GetDeployTaskListByType(modelType string) ([]*models.AiDeployInstanceTask, error) { func (s *AiStorage) GetDeployTaskListByType(modelType string) ([]*models.AiDeployInstanceTask, error) {

View File

@ -198,6 +198,8 @@ func (i *ImageInference) filterClusters() ([]*FilteredCluster, error) {
for _, cluster := range i.clusters { for _, cluster := range i.clusters {
var inferurls []*inference.InferUrl var inferurls []*inference.InferUrl
var clustertype string var clustertype string
var clusterName string
for _, instance := range i.instances { for _, instance := range i.instances {
clusterId := strconv.FormatInt(instance.ClusterId, 10) clusterId := strconv.FormatInt(instance.ClusterId, 10)
adapterId := strconv.FormatInt(instance.AdapterId, 10) adapterId := strconv.FormatInt(instance.AdapterId, 10)
@ -214,6 +216,7 @@ func (i *ImageInference) filterClusters() ([]*FilteredCluster, error) {
inferurls = append(inferurls, &url) inferurls = append(inferurls, &url)
clustertype = deployInstance.ClusterType clustertype = deployInstance.ClusterType
clusterName = deployInstance.ClusterName
} }
} }
if len(inferurls) == 0 { if len(inferurls) == 0 {
@ -224,7 +227,8 @@ func (i *ImageInference) filterClusters() ([]*FilteredCluster, error) {
var f FilteredCluster var f FilteredCluster
f.urls = inferurls f.urls = inferurls
f.clusterName = cluster.ClusterName f.clusterId = cluster.ClusterId
f.clusterName = clusterName
f.clusterType = clustertype f.clusterType = clustertype
f.imageNum = cluster.Replicas f.imageNum = cluster.Replicas
cs = append(cs, &f) cs = append(cs, &f)
@ -448,12 +452,19 @@ func (i *ImageInference) saveAiSubTasks(id int64, aiTaskList []*models.TaskAi, c
} }
func getInferResult(url string, file multipart.File, fileName string, clusterId string, clusterType string, inferAdapter map[string]map[string]inference.ICluster, adapterId string) (string, error) { func getInferResult(url string, file multipart.File, fileName string, clusterId string, clusterType string, inferAdapter map[string]map[string]inference.ICluster, adapterId string) (string, error) {
inferMap := inferAdapter[adapterId] adapter, found := inferAdapter[adapterId]
if !found {
return "", errors.New("adapterId not found")
}
iCluster, found := adapter[clusterId]
if !found {
return "", errors.New("clusterId not found")
}
switch clusterType { switch clusterType {
case storeLink.TYPE_OCTOPUS: case storeLink.TYPE_OCTOPUS:
r := http.Request{} r := http.Request{}
result, err := inferMap[clusterId].GetInferResult(r.Context(), url, file, fileName) result, err := iCluster.GetInferResult(r.Context(), url, file, fileName)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -1158,12 +1158,21 @@ func (o *OctopusLink) GetInferDeployInstance(ctx context.Context, id string) (*i
url := strings.Replace(resp.Payload.Notebook.Tasks[0].Url, FORWARD_SLASH, "", -1) url := strings.Replace(resp.Payload.Notebook.Tasks[0].Url, FORWARD_SLASH, "", -1)
inferUrl := DOMAIN + url inferUrl := DOMAIN + url
var card string
if resp.Payload.Notebook.Desc != "" {
str := strings.Split(resp.Payload.Notebook.Desc, FORWARD_SLASH)
if len(str) == 3 {
card = str[2]
}
}
ins.InstanceName = resp.Payload.Notebook.Name ins.InstanceName = resp.Payload.Notebook.Name
ins.InstanceId = resp.Payload.Notebook.Id ins.InstanceId = resp.Payload.Notebook.Id
ins.ClusterName = o.platform ins.ClusterName = o.platform
ins.Status = resp.Payload.Notebook.Status ins.Status = resp.Payload.Notebook.Status
ins.ClusterType = TYPE_OCTOPUS ins.ClusterType = TYPE_OCTOPUS
ins.InferUrl = inferUrl ins.InferUrl = inferUrl
ins.InferCard = card
return ins, nil return ins, nil
} }