From 46fac6b148780ba295481f42912d2990e1245df3 Mon Sep 17 00:00:00 2001 From: qiwang <1364512070@qq.com> Date: Tue, 27 Aug 2024 17:48:30 +0800 Subject: [PATCH] fix: Complete the modelarts createServeic of ai Former-commit-id: f31284ff45656057babe3d24252ae7c1939f3ce3 --- .../schedulers/option/inferOption.go | 7 ++++ internal/storeLink/modelarts.go | 34 +++++++++++++++++-- internal/storeLink/shuguangai.go | 1 + 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/internal/scheduler/schedulers/option/inferOption.go b/internal/scheduler/schedulers/option/inferOption.go index b5f45969..3083a82f 100644 --- a/internal/scheduler/schedulers/option/inferOption.go +++ b/internal/scheduler/schedulers/option/inferOption.go @@ -19,6 +19,13 @@ type InferOption struct { ResourceId string AlgorithmId string ImageId string + + //modelarts + InferType string + Specification string + Weight int32 + ModelId string + InstanceCount int32 } func (a InferOption) GetOptionType() string { diff --git a/internal/storeLink/modelarts.go b/internal/storeLink/modelarts.go index 50f96398..cf07ded9 100644 --- a/internal/storeLink/modelarts.go +++ b/internal/storeLink/modelarts.go @@ -260,6 +260,16 @@ func (m *ModelArtsLink) UploadAlgorithmCode(ctx context.Context, resourceType st return nil } +func (m *ModelArtsLink) GetModelId(ctx context.Context, option *option.AiOption, ifoption *option.InferOption) error { + req := &modelarts.ListModelReq{} + specResp, err := m.modelArtsRpc.ListModels(ctx, req) + if err != nil { + return err + } + + return nil +} + func (m *ModelArtsLink) GetTrainingTaskLog(ctx context.Context, taskId string, instanceNum string) (string, error) { req := &modelartsservice.GetTrainingJobLogsPreviewReq{ Platform: m.platform, @@ -364,7 +374,7 @@ func (m *ModelArtsLink) GenerateSubmitParams(ctx context.Context, option *option return nil } -func (m *ModelArtsLink) generateResourceId(ctx context.Context, option *option.AiOption) error { +func (m *ModelArtsLink) generateResourceId(ctx context.Context, option *option.AiOption, ifoption *option.InferOption) error { option.ResourceId = "modelarts.kat1.xlarge" return nil } @@ -541,5 +551,25 @@ func (m *ModelArtsLink) GetInferResult(ctx context.Context, url string, file mul } func (m *ModelArtsLink) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) { - return "", nil + + configParam := &modelarts.ServiceConfig{ + Specification: option.Specification, + Weight: option.Weight, + ModelId: option.ModelId, + InstanceCount: option.InstanceCount, + } + var configItems []*modelarts.ServiceConfig + configItems = append(configItems, configParam) + req := &modelarts.CreateServiceReq{ + Platform: m.platform, + Config: configItems, + InferType: option.InferType, + ServiceName: option.TaskName, + } + resp, err := m.modelArtsRpc.CreateService(ctx, req) + if err != nil { + return "", err + } + + return resp.ServiceId, nil } diff --git a/internal/storeLink/shuguangai.go b/internal/storeLink/shuguangai.go index a756de3f..40c10130 100644 --- a/internal/storeLink/shuguangai.go +++ b/internal/storeLink/shuguangai.go @@ -883,5 +883,6 @@ func (s *ShuguangAi) GetInferResult(ctx context.Context, url string, file multip } func (s *ShuguangAi) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) { + return "", nil }