You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ai.go 4.6 kB

4 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package participant
  2. import (
  3. "github.com/go-resty/resty/v2"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/database"
  5. "net/http"
  6. )
  7. const (
  8. // 算法路由
  9. AlgorithmById = "/ai/algorithm/get" //根据Id查询算法列表
  10. AlgorithmsList = "/ai/algorithm/list" //所有算法列表
  11. AlgorithmCreateById = "/ai/algorithm/create" //根据Id创建算法
  12. // 数据集路由
  13. DatasetCreateById = "/ai/dataset/create" //根据Id创建数据集
  14. // 模型相关路由
  15. ModelCreateById = "/ai/model/create" //根据Id创建模型
  16. // 资源相关路由
  17. ResourceSpecList = "/ai/resource/specs" //所有资源列表,根据参数 train or infer 查询资源
  18. ResourceTrainingById = "/ai/resource/train/get" //根据Id查询资源列表
  19. ResourceTrainingList = "/ai/resource/train/list" //所有训练资源列表
  20. // 任务相关路由
  21. TaskCreateTrain = "/ai/task/train"
  22. TaskResultSync = "/ai/task/sync"
  23. TaskLog = "/ai/task/log"
  24. TaskTrainingDetail = "/ai/task/train/detail"
  25. TaskInferenceDetail = "/ai/task/infer/detail"
  26. Localhost = "http://localhost:8080"
  27. )
  28. type Ai struct {
  29. store *database.AiStorage
  30. }
  31. func NewAi() (*Ai, error) {
  32. InitClient()
  33. return &Ai{}, nil
  34. }
  35. func (a *Ai) AlgorithmById(platformId string) (resp *Resp, err error) {
  36. respErr := &RespErr{}
  37. _, err = Request(Localhost+AlgorithmById, http.MethodGet, func(req *resty.Request) {
  38. req.SetQueryParams(map[string]string{
  39. "pfId": platformId,
  40. }).SetError(&respErr).SetResult(&resp)
  41. })
  42. if err != nil {
  43. return nil, err
  44. }
  45. return
  46. }
  47. func (a *Ai) AlgorithmCreateById(platformId string, param *CreateParam) (resp *Resp, err error) {
  48. respErr := &RespErr{}
  49. _, err = Request(Localhost+AlgorithmCreateById, http.MethodPost, func(req *resty.Request) {
  50. req.SetQueryParams(map[string]string{
  51. "pfId": platformId,
  52. }).SetBody(param).SetError(&respErr).SetResult(&resp)
  53. })
  54. if err != nil {
  55. return nil, err
  56. }
  57. return
  58. }
  59. func (a *Ai) DatasetCreateById(platformId string, param *CreateParam) (resp *Resp, err error) {
  60. respErr := &RespErr{}
  61. _, err = Request(Localhost+DatasetCreateById, http.MethodPost, func(req *resty.Request) {
  62. req.SetQueryParams(map[string]string{
  63. "pfId": platformId,
  64. }).SetBody(param).SetError(&respErr).SetResult(&resp)
  65. })
  66. if err != nil {
  67. return nil, err
  68. }
  69. return
  70. }
  71. func (a *Ai) ModelCreateById(platformId string, param *CreateParam) (resp *Resp, err error) {
  72. respErr := &RespErr{}
  73. _, err = Request(Localhost+ModelCreateById, http.MethodPost, func(req *resty.Request) {
  74. req.SetQueryParams(map[string]string{
  75. "pfId": platformId,
  76. }).SetBody(param).SetError(&respErr).SetResult(&resp)
  77. })
  78. if err != nil {
  79. return nil, err
  80. }
  81. return
  82. }
  83. func (a *Ai) TaskCreateTrain(platformId string, param *TaskCreateParam) (resp *Resp, err error) {
  84. respErr := &RespErr{}
  85. _, err = Request(Localhost+TaskCreateTrain, http.MethodPost, func(req *resty.Request) {
  86. req.SetQueryParams(map[string]string{
  87. "pfId": platformId,
  88. }).SetBody(param).SetError(&respErr).SetResult(&resp)
  89. })
  90. if err != nil {
  91. return nil, err
  92. }
  93. return
  94. }
  95. func (a *Ai) TaskResultSync(platformId string, param *TaskResultSyncParam) (resp *Resp, err error) {
  96. respErr := &RespErr{}
  97. _, err = Request(Localhost+TaskResultSync, http.MethodPost, func(req *resty.Request) {
  98. req.SetQueryParams(map[string]string{
  99. "pfId": platformId,
  100. }).SetBody(param).SetError(&respErr).SetResult(&resp)
  101. })
  102. if err != nil {
  103. return nil, err
  104. }
  105. return
  106. }
  107. func (a *Ai) TaskLog(platformId string, taskId string) (resp *Resp, err error) {
  108. respErr := &RespErr{}
  109. _, err = Request(Localhost+TaskLog, http.MethodGet, func(req *resty.Request) {
  110. req.SetQueryParams(map[string]string{
  111. "pfId": platformId,
  112. "taskId": taskId,
  113. }).SetError(&respErr).SetResult(&resp)
  114. })
  115. if err != nil {
  116. return nil, err
  117. }
  118. return
  119. }
  120. func (a *Ai) TaskTrainingDetail(platformId string, taskId string) (resp *Resp, err error) {
  121. respErr := &RespErr{}
  122. _, err = Request(Localhost+TaskTrainingDetail, http.MethodGet, func(req *resty.Request) {
  123. req.SetQueryParams(map[string]string{
  124. "pfId": platformId,
  125. "taskId": taskId,
  126. }).SetError(&respErr).SetResult(&resp)
  127. })
  128. if err != nil {
  129. return nil, err
  130. }
  131. return
  132. }
  133. func (a *Ai) TaskInferenceDetail(platformId string, taskId string) (resp *Resp, err error) {
  134. respErr := &RespErr{}
  135. _, err = Request(Localhost+TaskInferenceDetail, http.MethodGet, func(req *resty.Request) {
  136. req.SetQueryParams(map[string]string{
  137. "pfId": platformId,
  138. "taskId": taskId,
  139. }).SetError(&respErr).SetResult(&resp)
  140. })
  141. if err != nil {
  142. return nil, err
  143. }
  144. return
  145. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.