Former-commit-id: bcdc325f56
pull/303/head
| @@ -79,10 +79,8 @@ type ( | |||||
| TextToTextInferenceReq{ | TextToTextInferenceReq{ | ||||
| TaskName string `form:"taskName"` | TaskName string `form:"taskName"` | ||||
| TaskDesc string `form:"taskDesc"` | TaskDesc string `form:"taskDesc"` | ||||
| ModelName string `form:"modelName"` | |||||
| ModelType string `form:"modelType"` | ModelType string `form:"modelType"` | ||||
| AdapterId string `form:"adapterId"` | |||||
| AiClusterIds []string `form:"aiClusterIds"` | |||||
| InstanceId int64 `form:"instanceId"` | |||||
| } | } | ||||
| TextToTextInferenceResp{ | TextToTextInferenceResp{ | ||||
| @@ -114,8 +114,8 @@ func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeplo | |||||
| } | } | ||||
| type DeployTask struct { | 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"` | Instances []*models.AiInferDeployInstance `json:"instances,string"` | ||||
| } | } | ||||
| @@ -9,6 +9,7 @@ import ( | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference/textInference" | "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/svc" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" | "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" | ||||
| "strconv" | |||||
| ) | ) | ||||
| type TextToTextInferenceLogic struct { | 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) { | func (l *TextToTextInferenceLogic) TextToTextInference(req *types.TextToTextInferenceReq) (resp *types.TextToTextInferenceResp, err error) { | ||||
| resp = &types.TextToTextInferenceResp{} | 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 ") | |||||
| } | |||||
| adapterId := strconv.FormatInt(instance.AdapterId, 10) | |||||
| _, ok := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[opt.AdapterId] | |||||
| if !ok { | |||||
| return nil, errors.New("AdapterId does not exist") | |||||
| opt := &option.InferOption{ | |||||
| TaskName: req.TaskName, | |||||
| TaskDesc: req.TaskDesc, | |||||
| ModelType: req.ModelType, | |||||
| AdapterId: adapterId, | |||||
| } | } | ||||
| adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.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 { | if err != nil { | ||||
| return nil, err | 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 { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| @@ -17,30 +17,28 @@ type FilteredCluster struct { | |||||
| urls []*inference.InferUrl | urls []*inference.InferUrl | ||||
| clusterId string | clusterId string | ||||
| clusterName string | clusterName string | ||||
| clusterType string | |||||
| } | } | ||||
| type TextInference struct { | 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( | func New( | ||||
| inference ITextInference, | inference ITextInference, | ||||
| opt *option.InferOption, | opt *option.InferOption, | ||||
| storage *database.AiStorage, | storage *database.AiStorage, | ||||
| inferAdapter map[string]map[string]inference.ICluster, | |||||
| adapterName string) (*TextInference, error) { | adapterName string) (*TextInference, error) { | ||||
| return &TextInference{ | 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 | }, nil | ||||
| } | } | ||||
| @@ -22,11 +22,12 @@ type TextToText struct { | |||||
| opt *option.InferOption | opt *option.InferOption | ||||
| storage *database.AiStorage | storage *database.AiStorage | ||||
| inferAdapter map[string]map[string]inference.ICluster | inferAdapter map[string]map[string]inference.ICluster | ||||
| instance *models.AiInferDeployInstance | |||||
| cs []*FilteredCluster | 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 { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| @@ -64,7 +65,35 @@ func (tt *TextToText) SaveAiTask(id int64, adapterName string) error { | |||||
| return nil | 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 wg sync.WaitGroup | ||||
| var ch = make(chan *FilteredCluster, len(opt.AiClusterIds)) | var ch = make(chan *FilteredCluster, len(opt.AiClusterIds)) | ||||
| var cs []*FilteredCluster | var cs []*FilteredCluster | ||||
| @@ -5976,12 +5976,10 @@ type InferenceResult struct { | |||||
| } | } | ||||
| type TextToTextInferenceReq struct { | type TextToTextInferenceReq struct { | ||||
| TaskName string `form:"taskName"` | |||||
| TaskDesc string `form:"taskDesc"` | |||||
| ModelName string `form:"modelName"` | |||||
| ModelType string `form:"modelType"` | |||||
| AdapterId string `form:"adapterId"` | |||||
| AiClusterIds []string `form:"aiClusterIds"` | |||||
| TaskName string `form:"taskName"` | |||||
| TaskDesc string `form:"taskDesc"` | |||||
| ModelType string `form:"modelType"` | |||||
| InstanceId int64 `form:"instanceId"` | |||||
| } | } | ||||
| type TextToTextInferenceResp struct { | type TextToTextInferenceResp struct { | ||||