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.

modelarts.go 3.0 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package repo
  6. import (
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/log"
  10. "code.gitea.io/gitea/modules/modelarts"
  11. "net/http"
  12. "strconv"
  13. )
  14. func GetModelArtsNotebook(ctx *context.APIContext) {
  15. var (
  16. err error
  17. )
  18. jobID := ctx.Params(":jobid")
  19. repoID := ctx.Repo.Repository.ID
  20. job, err := models.GetRepoCloudBrainByJobID(repoID, jobID)
  21. if err != nil {
  22. ctx.NotFound(err)
  23. return
  24. }
  25. result, err := modelarts.GetJob(jobID)
  26. if err != nil {
  27. ctx.NotFound(err)
  28. return
  29. }
  30. job.Status = result.Status
  31. err = models.UpdateJob(job)
  32. if err != nil {
  33. log.Error("UpdateJob failed:", err)
  34. }
  35. ctx.JSON(http.StatusOK, map[string]interface{}{
  36. "JobID": jobID,
  37. "JobStatus": result.Status,
  38. })
  39. }
  40. func GetModelArtsTrainJob(ctx *context.APIContext) {
  41. var (
  42. err error
  43. )
  44. jobID := ctx.Params(":jobid")
  45. repoID := ctx.Repo.Repository.ID
  46. job, err := models.GetRepoCloudBrainByJobID(repoID, jobID)
  47. if err != nil {
  48. ctx.NotFound(err)
  49. return
  50. }
  51. result, err := modelarts.GetTrainJob(jobID, strconv.FormatInt(job.VersionID, 10))
  52. if err != nil {
  53. ctx.NotFound(err)
  54. return
  55. }
  56. job.Status = modelarts.TransTrainJobStatus(result.IntStatus)
  57. job.Duration = result.Duration
  58. job.TrainJobDuration = result.TrainJobDuration
  59. err = models.UpdateJob(job)
  60. if err != nil {
  61. log.Error("UpdateJob failed:", err)
  62. }
  63. ctx.JSON(http.StatusOK, map[string]interface{}{
  64. "JobID": jobID,
  65. "JobStatus": job.Status,
  66. "JobDuration": job.Duration,
  67. })
  68. }
  69. func TrainJobGetLog(ctx *context.APIContext) {
  70. var (
  71. err error
  72. )
  73. log.Info("test")
  74. var jobID = ctx.Params(":jobid")
  75. var logFileName = ctx.Query("file_name")
  76. var baseLine = ctx.Query("base_line")
  77. var order = ctx.Query("order")
  78. if order != modelarts.OrderDesc && order != modelarts.OrderAsc {
  79. log.Error("order(%s) check failed", order)
  80. ctx.JSON(http.StatusBadRequest, map[string]interface{}{
  81. "err_msg": "order check failed",
  82. })
  83. return
  84. }
  85. task, err := models.GetCloudbrainByJobID(jobID)
  86. if err != nil {
  87. log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error())
  88. ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
  89. "err_msg": "GetCloudbrainByJobID failed",
  90. })
  91. return
  92. }
  93. result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), baseLine, logFileName, order, modelarts.Lines)
  94. if err != nil {
  95. log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error())
  96. ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
  97. "err_msg": "GetTrainJobLog failed",
  98. })
  99. return
  100. }
  101. ctx.JSON(http.StatusOK, map[string]interface{}{
  102. "JobID": jobID,
  103. "StartLine": result.StartLine,
  104. "EndLine": result.EndLine,
  105. "Content": result.Content,
  106. "Lines": result.Lines,
  107. })
  108. }