fix: Complete the modelarts createServeic of ai
Former-commit-id: 2b5e5f5036f7e77bfdf4f2b8339e3046d6f41ddc
This commit is contained in:
parent
2d79050b09
commit
eeddff6a02
|
@ -27,7 +27,7 @@ ModelArtsRpcConf:
|
||||||
Endpoints:
|
Endpoints:
|
||||||
- 127.0.0.1:2002
|
- 127.0.0.1:2002
|
||||||
NonBlock: true
|
NonBlock: true
|
||||||
Timeout: 20000
|
Timeout: 500000
|
||||||
|
|
||||||
#rpc
|
#rpc
|
||||||
ModelArtsImgRpcConf:
|
ModelArtsImgRpcConf:
|
||||||
|
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice"
|
"gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice"
|
||||||
"gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
|
"gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
|
||||||
modelartsclient "gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
|
modelartsclient "gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
|
||||||
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -334,7 +335,6 @@ func (m *ModelArtsLink) getSourceLocationFromImages(ctx context.Context, option
|
||||||
for _, ListImages := range ListImagesResp.Data {
|
for _, ListImages := range ListImagesResp.Data {
|
||||||
if ListImages.Name == option.ModelName {
|
if ListImages.Name == option.ModelName {
|
||||||
m.SourceLocation = ListImages.SwrPath
|
m.SourceLocation = ListImages.SwrPath
|
||||||
//m.Version = ListImages.Mo
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -367,47 +367,45 @@ func (m *ModelArtsLink) GetModelId(ctx context.Context, option *option.InferOpti
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get AI Application List
|
func (m *ModelArtsLink) GetModel(ctx context.Context, option *option.InferOption) string {
|
||||||
func (m *ModelArtsLink) GetModelStatus(ctx context.Context, option *option.InferOption) error {
|
|
||||||
req := &modelarts.ShowModelReq{
|
req := &modelarts.ShowModelReq{
|
||||||
Platform: m.platform,
|
Platform: m.platform,
|
||||||
ModelId: option.ModelId,
|
ModelId: option.ModelId,
|
||||||
}
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second)
|
||||||
|
defer cancel()
|
||||||
ShowModelsResp, err := m.modelArtsRpc.ShowModels(ctx, req)
|
ShowModelsResp, err := m.modelArtsRpc.ShowModels(ctx, req)
|
||||||
if err != nil {
|
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 {
|
if ShowModelsResp.Code != 200 {
|
||||||
return errors.New("failed to get ListModels")
|
errors.New("failed to get findModelsStatus")
|
||||||
|
}
|
||||||
|
return ShowModelsResp.ShowModelDetail.ModelStatus
|
||||||
}
|
}
|
||||||
ModelStatus := ShowModelsResp.ShowModelDetail.ModelStatus
|
|
||||||
|
|
||||||
|
// Get AI Application List
|
||||||
|
func (m *ModelArtsLink) GetModelStatus(ctx context.Context, option *option.InferOption) error {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
//model := MyModel{Status: "draft"}
|
|
||||||
|
|
||||||
// 使用goroutine进行轮询
|
// 使用goroutine进行轮询
|
||||||
go func() {
|
//defer wg.Done()
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
status := ModelStatus
|
status := m.GetModel(ctx, option)
|
||||||
if status == "published" {
|
if status == "published" {
|
||||||
fmt.Println("Model is now published.")
|
fmt.Println("Model is now published.")
|
||||||
break // 一旦状态变为published,就退出循环
|
break // 一旦状态变为published,就退出循环
|
||||||
}
|
}
|
||||||
fmt.Println("Waiting for model to be published...")
|
fmt.Println("Waiting for model to be published...")
|
||||||
time.Sleep(2 * time.Second) // 等待一段时间后再次检查
|
time.Sleep(5 * time.Second) // 等待一段时间后再次检查
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
// 等待goroutine完成
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// 在这里执行模型状态为published后需要进行的操作
|
// 在这里执行模型状态为published后需要进行的操作
|
||||||
fmt.Println("Continuing with the program...")
|
fmt.Println("Continuing with the program...")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -773,6 +771,8 @@ func (m *ModelArtsLink) CreateInferDeployInstance(ctx context.Context, option *o
|
||||||
InferType: "real-time",
|
InferType: "real-time",
|
||||||
ServiceName: option.TaskName,
|
ServiceName: option.TaskName,
|
||||||
}
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second)
|
||||||
|
defer cancel()
|
||||||
resp, err := m.modelArtsRpc.CreateService(ctx, req)
|
resp, err := m.modelArtsRpc.CreateService(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
Loading…
Reference in New Issue