fix: Complete the modelarts createServeic of ai

Former-commit-id: 2b5e5f5036f7e77bfdf4f2b8339e3046d6f41ddc
This commit is contained in:
qiwang 2024-09-06 15:09:00 +08:00
parent 2d79050b09
commit eeddff6a02
2 changed files with 27 additions and 27 deletions

View File

@ -27,7 +27,7 @@ ModelArtsRpcConf:
Endpoints:
- 127.0.0.1:2002
NonBlock: true
Timeout: 20000
Timeout: 500000
#rpc
ModelArtsImgRpcConf:

View File

@ -28,6 +28,7 @@ import (
"gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice"
"gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
modelartsclient "gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
"log"
"mime/multipart"
"strconv"
"strings"
@ -334,7 +335,6 @@ func (m *ModelArtsLink) getSourceLocationFromImages(ctx context.Context, option
for _, ListImages := range ListImagesResp.Data {
if ListImages.Name == option.ModelName {
m.SourceLocation = ListImages.SwrPath
//m.Version = ListImages.Mo
return nil
}
}
@ -367,47 +367,45 @@ func (m *ModelArtsLink) GetModelId(ctx context.Context, option *option.InferOpti
return nil
}
// Get AI Application List
func (m *ModelArtsLink) GetModelStatus(ctx context.Context, option *option.InferOption) error {
func (m *ModelArtsLink) GetModel(ctx context.Context, option *option.InferOption) string {
req := &modelarts.ShowModelReq{
Platform: m.platform,
ModelId: option.ModelId,
}
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second)
defer cancel()
ShowModelsResp, err := m.modelArtsRpc.ShowModels(ctx, req)
if err != nil {
return err
if err == context.DeadlineExceeded {
log.Println("Request timed out")
// 重试请求或其他处理
} else {
log.Fatalf("could not call method: %v", err)
}
}
if ShowModelsResp.Code != 200 {
return errors.New("failed to get ListModels")
errors.New("failed to get findModelsStatus")
}
ModelStatus := ShowModelsResp.ShowModelDetail.ModelStatus
return ShowModelsResp.ShowModelDetail.ModelStatus
}
// Get AI Application List
func (m *ModelArtsLink) GetModelStatus(ctx context.Context, option *option.InferOption) error {
var wg sync.WaitGroup
wg.Add(1)
//model := MyModel{Status: "draft"}
// 使用goroutine进行轮询
go func() {
defer wg.Done()
for {
status := ModelStatus
if status == "published" {
fmt.Println("Model is now published.")
break // 一旦状态变为published就退出循环
}
fmt.Println("Waiting for model to be published...")
time.Sleep(2 * time.Second) // 等待一段时间后再次检查
//defer wg.Done()
for {
status := m.GetModel(ctx, option)
if status == "published" {
fmt.Println("Model is now published.")
break // 一旦状态变为published就退出循环
}
}()
// 等待goroutine完成
wg.Wait()
fmt.Println("Waiting for model to be published...")
time.Sleep(5 * time.Second) // 等待一段时间后再次检查
}
// 在这里执行模型状态为published后需要进行的操作
fmt.Println("Continuing with the program...")
return nil
}
@ -773,6 +771,8 @@ func (m *ModelArtsLink) CreateInferDeployInstance(ctx context.Context, option *o
InferType: "real-time",
ServiceName: option.TaskName,
}
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second)
defer cancel()
resp, err := m.modelArtsRpc.CreateService(ctx, req)
if err != nil {
return "", err