mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 07:37:23 +00:00
* feat: channel affinity * feat: channel affinity -> model setting * fix: channel affinity * feat: channel affinity op * feat: channel_type setting * feat: clean * feat: cache supports both memory and Redis. * feat: Optimise ui/ux * feat: Optimise ui/ux * feat: Optimise codex usage ui/ux * feat: Optimise ui/ux * feat: Optimise ui/ux * feat: Optimise ui/ux * feat: If the affinitized channel fails and a retry succeeds on another channel, update the affinity to the successful channel
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package controller
|
||
|
||
import (
|
||
"net/http"
|
||
"strings"
|
||
|
||
"github.com/QuantumNous/new-api/service"
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
func GetChannelAffinityCacheStats(c *gin.Context) {
|
||
stats := service.GetChannelAffinityCacheStats()
|
||
c.JSON(http.StatusOK, gin.H{
|
||
"success": true,
|
||
"message": "",
|
||
"data": stats,
|
||
})
|
||
}
|
||
|
||
func ClearChannelAffinityCache(c *gin.Context) {
|
||
all := strings.TrimSpace(c.Query("all"))
|
||
ruleName := strings.TrimSpace(c.Query("rule_name"))
|
||
|
||
if all == "true" {
|
||
deleted := service.ClearChannelAffinityCacheAll()
|
||
c.JSON(http.StatusOK, gin.H{
|
||
"success": true,
|
||
"message": "",
|
||
"data": gin.H{
|
||
"deleted": deleted,
|
||
},
|
||
})
|
||
return
|
||
}
|
||
|
||
if ruleName == "" {
|
||
c.JSON(http.StatusBadRequest, gin.H{
|
||
"success": false,
|
||
"message": "缺少参数:rule_name,或使用 all=true 清空全部",
|
||
})
|
||
return
|
||
}
|
||
|
||
deleted, err := service.ClearChannelAffinityCacheByRuleName(ruleName)
|
||
if err != nil {
|
||
c.JSON(http.StatusBadRequest, gin.H{
|
||
"success": false,
|
||
"message": err.Error(),
|
||
})
|
||
return
|
||
}
|
||
|
||
c.JSON(http.StatusOK, gin.H{
|
||
"success": true,
|
||
"message": "",
|
||
"data": gin.H{
|
||
"deleted": deleted,
|
||
},
|
||
})
|
||
}
|