updated imageinference logics

Former-commit-id: 1bb4a47ac943ee12a0d92ce37820af58b155641e
This commit is contained in:
tzwang 2024-08-28 15:22:41 +08:00
parent a60e97134d
commit 3c3d45fe62
5 changed files with 54 additions and 42 deletions

View File

@ -82,9 +82,15 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere
//}
//
var cs []*strategy.AssignedCluster
var adapterName string
adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
if err != nil {
return nil, err
}
if opt.Strategy != "" {
return nil, errors.New("strategy is empty")
}
var strat strategy.Strategy
switch opt.Strategy {
case strategy.STATIC_WEIGHT:
@ -110,20 +116,7 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere
}
}
name, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
if err != nil {
return nil, err
}
adapterName = name
}
//else {
// for i, instance := range req.Instances {
//
// }
//}
imageInfer, err := imageInference.New(imageInference.NewImageClassification(), ts, cs, req.Instances, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName)
imageInfer, err := imageInference.New(imageInference.NewImageClassification(), ts, clusters, req.Instances, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName)
if err != nil {
return nil, err
}

View File

@ -131,7 +131,7 @@ func (i *ImageInference) saveTask() (int64, error) {
return 0, err
}
i.storage.AddNoticeInfo(i.opt.AdapterId, i.adapterName, "", "", i.opt.TaskName, "create", "任务创建中")
i.storage.AddNoticeInfo("", "", "", "", i.opt.TaskName, "create", "任务创建中")
return id, nil
}
@ -197,21 +197,33 @@ func (i *ImageInference) filterClusters() ([]*FilteredCluster, error) {
var cs []*FilteredCluster
for _, cluster := range i.clusters {
var inferurls []*inference.InferUrl
var clustertype string
for _, instance := range i.instances {
if cluster.ClusterId == instance.ClusterId {
r := http.Request{}
deployInstance, err := i.inferAdapter[instance.AdapterId][instance.ClusterId].GetInferDeployInstance(r.Context(), instance.InstanceId)
if err != nil {
return nil, err
continue
}
var url inference.InferUrl
url.Url = deployInstance.InferUrl
url.Card = deployInstance.InferCard
inferurls = append(inferurls, &url)
clustertype = deployInstance.ClusterType
}
}
if len(inferurls) == 0 {
continue
}
i.inference.AppendRoute(inferurls)
var f FilteredCluster
f.urls = inferurls
f.clusterName = cluster.ClusterName
f.clusterType = clustertype
f.imageNum = cluster.Replicas
cs = append(cs, &f)
}
return cs, nil

View File

@ -9,7 +9,7 @@ import (
)
const (
TEXTTOIMAGE = "text-to-image"
TEXTTOIMAGE = "generate_image"
TEXTTOIMAGE_AiTYPE = "14"
)

View File

@ -79,9 +79,11 @@ func filterClusters(opt *option.InferOption, storage *database.AiStorage, inferA
wg.Done()
return
}
for i, _ := range clusterInferUrl.InferUrls {
clusterInferUrl.InferUrls[i].Url = clusterInferUrl.InferUrls[i].Url + inference.FORWARD_SLASH + CHAT
}
clusterName, _ := storage.GetClusterNameById(cId)
var f FilteredCluster

View File

@ -1154,11 +1154,16 @@ func (o *OctopusLink) GetInferDeployInstance(ctx context.Context, id string) (*i
if resp.Payload == nil {
return nil, errors.New("instance does not exist")
}
url := strings.Replace(resp.Payload.Notebook.Tasks[0].Url, FORWARD_SLASH, "", -1)
inferUrl := DOMAIN + url
ins.InstanceName = resp.Payload.Notebook.Name
ins.InstanceId = resp.Payload.Notebook.Id
ins.ClusterName = o.platform
ins.Status = resp.Payload.Notebook.Status
ins.ClusterType = TYPE_OCTOPUS
ins.InferUrl = inferUrl
return ins, nil
}