monitor.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package controller
  2. import (
  3. "net/http"
  4. "strconv"
  5. "github.com/gin-gonic/gin"
  6. "github.com/labring/sealos/service/aiproxy/middleware"
  7. "github.com/labring/sealos/service/aiproxy/monitor"
  8. )
  9. func GetAllChannelModelErrorRates(c *gin.Context) {
  10. rates, err := monitor.GetAllChannelModelErrorRates(c.Request.Context())
  11. if err != nil {
  12. middleware.ErrorResponse(c, http.StatusOK, err.Error())
  13. return
  14. }
  15. c.JSON(http.StatusOK, rates)
  16. }
  17. func GetChannelModelErrorRates(c *gin.Context) {
  18. channelID := c.Param("id")
  19. channelIDInt, err := strconv.ParseInt(channelID, 10, 64)
  20. if err != nil {
  21. middleware.ErrorResponse(c, http.StatusOK, "Invalid channel ID")
  22. return
  23. }
  24. rates, err := monitor.GetChannelModelErrorRates(c.Request.Context(), channelIDInt)
  25. if err != nil {
  26. middleware.ErrorResponse(c, http.StatusOK, err.Error())
  27. return
  28. }
  29. c.JSON(http.StatusOK, rates)
  30. }
  31. func ClearAllModelErrors(c *gin.Context) {
  32. err := monitor.ClearAllModelErrors(c.Request.Context())
  33. if err != nil {
  34. middleware.ErrorResponse(c, http.StatusOK, err.Error())
  35. return
  36. }
  37. c.Status(http.StatusNoContent)
  38. }
  39. func ClearChannelAllModelErrors(c *gin.Context) {
  40. channelID := c.Param("id")
  41. channelIDInt, err := strconv.ParseInt(channelID, 10, 64)
  42. if err != nil {
  43. middleware.ErrorResponse(c, http.StatusOK, "Invalid channel ID")
  44. return
  45. }
  46. err = monitor.ClearChannelAllModelErrors(c.Request.Context(), int(channelIDInt))
  47. if err != nil {
  48. middleware.ErrorResponse(c, http.StatusOK, err.Error())
  49. return
  50. }
  51. c.Status(http.StatusNoContent)
  52. }
  53. func ClearChannelModelErrors(c *gin.Context) {
  54. channelID := c.Param("id")
  55. model := c.Param("model")
  56. channelIDInt, err := strconv.ParseInt(channelID, 10, 64)
  57. if err != nil {
  58. middleware.ErrorResponse(c, http.StatusOK, "Invalid channel ID")
  59. return
  60. }
  61. err = monitor.ClearChannelModelErrors(c.Request.Context(), model, int(channelIDInt))
  62. if err != nil {
  63. middleware.ErrorResponse(c, http.StatusOK, err.Error())
  64. return
  65. }
  66. c.Status(http.StatusNoContent)
  67. }
  68. func GetModelsErrorRate(c *gin.Context) {
  69. rates, err := monitor.GetModelsErrorRate(c.Request.Context())
  70. if err != nil {
  71. middleware.ErrorResponse(c, http.StatusOK, err.Error())
  72. return
  73. }
  74. c.JSON(http.StatusOK, rates)
  75. }
  76. func GetAllBannedModelChannels(c *gin.Context) {
  77. channels, err := monitor.GetAllBannedModelChannels(c.Request.Context())
  78. if err != nil {
  79. middleware.ErrorResponse(c, http.StatusOK, err.Error())
  80. return
  81. }
  82. c.JSON(http.StatusOK, channels)
  83. }