updated texttotextinference logic

Former-commit-id: 74abd736b1765b4fbe4400b1a59d18577043630e
This commit is contained in:
tzwang 2024-09-04 16:37:31 +08:00
parent f7e3e91887
commit ec64ec2007
4 changed files with 63 additions and 31 deletions

View File

@ -114,8 +114,8 @@ 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"`
} }

View File

@ -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, instance, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(req.InstanceId)
TaskDesc: req.TaskDesc, if err != nil {
AdapterId: req.AdapterId, return nil, err
AiClusterIds: req.AiClusterIds, }
ModelName: req.ModelName, if instance == nil {
ModelType: req.ModelType, return nil, errors.New("instance is empty ")
} }
_, ok := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[opt.AdapterId] adapterId := strconv.FormatInt(instance.AdapterId, 10)
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
} }

View File

@ -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 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
} }
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, 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
} }

View File

@ -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