From ec64ec20072e7d9c19bd0221acdb9e01c678fdb0 Mon Sep 17 00:00:00 2001 From: tzwang Date: Wed, 4 Sep 2024 16:37:31 +0800 Subject: [PATCH] updated texttotextinference logic Former-commit-id: 74abd736b1765b4fbe4400b1a59d18577043630e --- .../inference/deployinstancelistlogic.go | 6 ++-- .../inference/texttotextinferencelogic.go | 29 ++++++++------- .../inference/textInference/textInference.go | 24 ++++++------- .../inference/textInference/textToText.go | 35 +++++++++++++++++-- 4 files changed, 63 insertions(+), 31 deletions(-) diff --git a/internal/logic/inference/deployinstancelistlogic.go b/internal/logic/inference/deployinstancelistlogic.go index a6794bef..6f17c7cd 100644 --- a/internal/logic/inference/deployinstancelistlogic.go +++ b/internal/logic/inference/deployinstancelistlogic.go @@ -114,8 +114,8 @@ func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeplo } type DeployTask struct { - Id int64 `json:"id,string"` - Name string - Desc string + Id int64 `json:"id,string"` + Name string `json:"name"` + Desc string `json:"desc"` Instances []*models.AiInferDeployInstance `json:"instances,string"` } diff --git a/internal/logic/inference/texttotextinferencelogic.go b/internal/logic/inference/texttotextinferencelogic.go index 2507f2c6..0d73ec1d 100644 --- a/internal/logic/inference/texttotextinferencelogic.go +++ b/internal/logic/inference/texttotextinferencelogic.go @@ -9,6 +9,7 @@ import ( "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference/textInference" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" + "strconv" ) type TextToTextInferenceLogic struct { @@ -27,27 +28,31 @@ func NewTextToTextInferenceLogic(ctx context.Context, svcCtx *svc.ServiceContext func (l *TextToTextInferenceLogic) TextToTextInference(req *types.TextToTextInferenceReq) (resp *types.TextToTextInferenceResp, err error) { resp = &types.TextToTextInferenceResp{} - opt := &option.InferOption{ - TaskName: req.TaskName, - TaskDesc: req.TaskDesc, - AdapterId: req.AdapterId, - AiClusterIds: req.AiClusterIds, - ModelName: req.ModelName, - ModelType: req.ModelType, + + instance, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(req.InstanceId) + if err != nil { + return nil, err + } + if instance == nil { + return nil, errors.New("instance is empty ") } - _, ok := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[opt.AdapterId] - if !ok { - return nil, errors.New("AdapterId does not exist") + adapterId := strconv.FormatInt(instance.AdapterId, 10) + + opt := &option.InferOption{ + TaskName: req.TaskName, + TaskDesc: req.TaskDesc, + ModelType: req.ModelType, + AdapterId: adapterId, } adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId) - inType, err := textInference.NewTextToText(opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap) + infer, err := textInference.NewTextToText(opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, instance) if err != nil { return nil, err } - textInfer, err := textInference.New(inType, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName) + textInfer, err := textInference.New(infer, opt, l.svcCtx.Scheduler.AiStorages, adapterName) if err != nil { return nil, err } diff --git a/internal/scheduler/service/inference/textInference/textInference.go b/internal/scheduler/service/inference/textInference/textInference.go index c0709c21..239754fa 100644 --- a/internal/scheduler/service/inference/textInference/textInference.go +++ b/internal/scheduler/service/inference/textInference/textInference.go @@ -17,30 +17,28 @@ type FilteredCluster struct { urls []*inference.InferUrl clusterId string clusterName string + clusterType string } type TextInference struct { - inference ITextInference - opt *option.InferOption - storage *database.AiStorage - inferAdapter map[string]map[string]inference.ICluster - errMap map[string]string - adapterName string + inference ITextInference + opt *option.InferOption + storage *database.AiStorage + errMap map[string]string + adapterName string } func New( inference ITextInference, opt *option.InferOption, storage *database.AiStorage, - inferAdapter map[string]map[string]inference.ICluster, adapterName string) (*TextInference, error) { return &TextInference{ - inference: inference, - opt: opt, - storage: storage, - inferAdapter: inferAdapter, - adapterName: adapterName, - errMap: make(map[string]string), + inference: inference, + opt: opt, + storage: storage, + adapterName: adapterName, + errMap: make(map[string]string), }, nil } diff --git a/internal/scheduler/service/inference/textInference/textToText.go b/internal/scheduler/service/inference/textInference/textToText.go index 3851a35e..e631049e 100644 --- a/internal/scheduler/service/inference/textInference/textToText.go +++ b/internal/scheduler/service/inference/textInference/textToText.go @@ -22,11 +22,12 @@ type TextToText struct { opt *option.InferOption storage *database.AiStorage inferAdapter map[string]map[string]inference.ICluster + instance *models.AiInferDeployInstance cs []*FilteredCluster } -func NewTextToText(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster) (*TextToText, error) { - cs, err := filterClusters(opt, storage, inferAdapter) +func NewTextToText(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster, instance *models.AiInferDeployInstance) (*TextToText, error) { + cs, err := filterClusters(inferAdapter, instance) if err != nil { return nil, err } @@ -64,7 +65,35 @@ func (tt *TextToText) SaveAiTask(id int64, adapterName string) error { return nil } -func filterClusters(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster) ([]*FilteredCluster, error) { +func filterClusters(inferAdapter map[string]map[string]inference.ICluster, instance *models.AiInferDeployInstance) ([]*FilteredCluster, error) { + var cs []*FilteredCluster + var inferurls []*inference.InferUrl + clusterId := strconv.FormatInt(instance.ClusterId, 10) + adapterId := strconv.FormatInt(instance.AdapterId, 10) + r := http.Request{} + deployInstance, err := inferAdapter[adapterId][clusterId].GetInferDeployInstance(r.Context(), instance.InstanceId) + if err != nil { + return nil, err + } + var url inference.InferUrl + url.Url = deployInstance.InferUrl + inference.FORWARD_SLASH + CHAT + url.Card = deployInstance.InferCard + inferurls = append(inferurls, &url) + + clusterType := deployInstance.ClusterType + clusterName := deployInstance.ClusterName + + var f FilteredCluster + f.urls = inferurls + f.clusterId = clusterId + f.clusterName = clusterName + f.clusterType = clusterType + cs = append(cs, &f) + + return cs, nil +} + +func filterClustersTemp(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster) ([]*FilteredCluster, error) { var wg sync.WaitGroup var ch = make(chan *FilteredCluster, len(opt.AiClusterIds)) var cs []*FilteredCluster