From 837d9401c0dda457cf249a099b170d0a223e9b7d Mon Sep 17 00:00:00 2001 From: qiwang <1364512070@qq.com> Date: Fri, 30 Aug 2024 10:17:59 +0800 Subject: [PATCH] fix: Complete the modelarts createServeic of ai Former-commit-id: 1d51c0bcbdf224ed77fadc75ebf8d0a33cd0fbcc --- internal/storeLink/modelarts.go | 38 +++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/internal/storeLink/modelarts.go b/internal/storeLink/modelarts.go index 3c76bfcc..cbf03c53 100644 --- a/internal/storeLink/modelarts.go +++ b/internal/storeLink/modelarts.go @@ -261,13 +261,25 @@ func (m *ModelArtsLink) UploadAlgorithmCode(ctx context.Context, resourceType st } func (m *ModelArtsLink) GetModelId(ctx context.Context, option *option.AiOption, ifoption *option.InferOption) error { - req := &modelarts.ListModelReq{} - specResp, err := m.modelArtsRpc.ListModels(ctx, req) + req := &modelarts.ListModelReq{ + Platform: m.platform, + Limit: int64(m.pageIndex), + Offset: int64(m.pageSize), + ModelName: option.ModelName, + //ModelType: option.ModelType, + } + ListResp, err := m.modelArtsRpc.ListModels(ctx, req) + for _, Models := range ListResp.Models { + if Models.ModelName == option.ModelName { + ifoption.ModelId = Models.ModelId + return nil + } + } if err != nil { return err } - return nil + return errors.New("failed to set ModelId") } func (m *ModelArtsLink) GetTrainingTaskLog(ctx context.Context, taskId string, instanceNum string) (string, error) { @@ -347,7 +359,7 @@ func (m *ModelArtsLink) Execute(ctx context.Context, option *option.AiOption) (i } func (m *ModelArtsLink) GenerateSubmitParams(ctx context.Context, option *option.AiOption) error { - err := m.generateResourceId(ctx, option) + err := m.generateResourceId(ctx, option, nil) if err != nil { return err } @@ -552,8 +564,13 @@ func (m *ModelArtsLink) GetInferResult(ctx context.Context, url string, file mul func (m *ModelArtsLink) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) { + err := m.GetModelId(ctx, nil, option) + if err != nil { + return "", err + } + configParam := &modelarts.ServiceConfig{ - Specification: option.Specification, + Specification: "modelarts.kat1.xlarge.al", Weight: option.Weight, ModelId: option.ModelId, InstanceCount: option.InstanceCount, @@ -575,5 +592,14 @@ func (m *ModelArtsLink) CreateInferDeployInstance(ctx context.Context, option *o } func (m *ModelArtsLink) CheckModelExistence(ctx context.Context, name string, mtype string) bool { - return false + ifoption := &option.InferOption{ + ModelName: name, + ModelType: mtype, + } + err := m.GetModelId(ctx, nil, ifoption) + if err != nil { + return false + } + + return true }