Merge pull request 'updated texttotextinference logics' (#301) from tzwang/pcm-coordinator:master into master
Former-commit-id: bcdc325f56973b49109a903a89c86b161b9a14f4
This commit is contained in:
commit
90613ec81c
|
@ -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"`
|
InstanceId int64 `form:"instanceId"`
|
||||||
AiClusterIds []string `form:"aiClusterIds"`
|
|
||||||
}
|
}
|
||||||
TextToTextInferenceResp{
|
TextToTextInferenceResp{
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeplo
|
||||||
|
|
||||||
type DeployTask struct {
|
type DeployTask struct {
|
||||||
Id int64 `json:"id,string"`
|
Id int64 `json:"id,string"`
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Desc string
|
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{}
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
opt := &option.InferOption{
|
opt := &option.InferOption{
|
||||||
TaskName: req.TaskName,
|
TaskName: req.TaskName,
|
||||||
TaskDesc: req.TaskDesc,
|
TaskDesc: req.TaskDesc,
|
||||||
AdapterId: req.AdapterId,
|
|
||||||
AiClusterIds: req.AiClusterIds,
|
|
||||||
ModelName: req.ModelName,
|
|
||||||
ModelType: req.ModelType,
|
ModelType: req.ModelType,
|
||||||
}
|
AdapterId: adapterId,
|
||||||
|
|
||||||
_, ok := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[opt.AdapterId]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("AdapterId does not exist")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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,13 +17,13 @@ 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
|
inference ITextInference
|
||||||
opt *option.InferOption
|
opt *option.InferOption
|
||||||
storage *database.AiStorage
|
storage *database.AiStorage
|
||||||
inferAdapter map[string]map[string]inference.ICluster
|
|
||||||
errMap map[string]string
|
errMap map[string]string
|
||||||
adapterName string
|
adapterName string
|
||||||
}
|
}
|
||||||
|
@ -32,13 +32,11 @@ 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,
|
inference: inference,
|
||||||
opt: opt,
|
opt: opt,
|
||||||
storage: storage,
|
storage: storage,
|
||||||
inferAdapter: inferAdapter,
|
|
||||||
adapterName: adapterName,
|
adapterName: adapterName,
|
||||||
errMap: make(map[string]string),
|
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) {
|
func NewTextToText(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster, instance *models.AiInferDeployInstance) (*TextToText, error) {
|
||||||
cs, err := filterClusters(opt, storage, inferAdapter)
|
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
|
||||||
|
|
|
@ -5978,10 +5978,8 @@ type InferenceResult struct {
|
||||||
type TextToTextInferenceReq struct {
|
type TextToTextInferenceReq struct {
|
||||||
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"`
|
InstanceId int64 `form:"instanceId"`
|
||||||
AiClusterIds []string `form:"aiClusterIds"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TextToTextInferenceResp struct {
|
type TextToTextInferenceResp struct {
|
||||||
|
|
Loading…
Reference in New Issue