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 2.9 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
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. err = models.UpdateJob(job)
  58. if err != nil {
  59. log.Error("UpdateJob failed:", err)
  60. }
  61. ctx.JSON(http.StatusOK, map[string]interface{}{
  62. "JobID": jobID,
  63. "JobStatus": job.Status,
  64. })
  65. }
  66. func TrainJobGetLog(ctx *context.APIContext) {
  67. var (
  68. err error
  69. )
  70. log.Info("test")
  71. var jobID = ctx.Params(":jobid")
  72. var logFileName = ctx.Query("file_name")
  73. var baseLine = ctx.Query("base_line")
  74. var order = ctx.Query("order")
  75. if order != modelarts.OrderDesc && order != modelarts.OrderAsc {
  76. log.Error("order(%s) check failed", order)
  77. ctx.JSON(http.StatusBadRequest, map[string]interface{}{
  78. "err_msg": "order check failed",
  79. })
  80. return
  81. }
  82. task, err := models.GetCloudbrainByJobID(jobID)
  83. if err != nil {
  84. log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error())
  85. ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
  86. "err_msg": "GetCloudbrainByJobID failed",
  87. })
  88. return
  89. }
  90. result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), baseLine, logFileName, order, 20)
  91. if err != nil {
  92. log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error())
  93. ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
  94. "err_msg": "GetTrainJobLog failed",
  95. })
  96. return
  97. }
  98. ctx.JSON(http.StatusOK, map[string]interface{}{
  99. "JobID": jobID,
  100. "StartLine": result.StartLine,
  101. "EndLine": result.EndLine,
  102. "Content": result.Content,
  103. "Lines": result.Lines,
  104. })
  105. }