feat: sync deployed v1.0.0-rc.38-custom.67

This commit is contained in:
cneicy committed 2026-10-06 00:07:10 +08:00
1 parent d2e03ab7e8
commit ffc8cf56db
154 files changed
+39540 -20509

No files matched your search

+5
View File
@@ -450,6 +450,11 @@ func TokenAuth() func(c *gin.Context) {
return
}
if err := model.LoadPersonalGroupRatios(c, userCache.Id); err != nil {
abortWithOpenAiMessage(c, http.StatusServiceUnavailable, "User pricing temporarily unavailable")
return
}
defer service.ReleasePoolProbes(c)
userCache.WriteContext(c)
userGroup := userCache.Group
+22 -5
View File
@@ -27,13 +27,16 @@ import (
)
type ModelRequest struct {
Model string `json:"model"`
Group string `json:"group,omitempty"`
Model string `json:"model"`
Group string `json:"group,omitempty"`
Stream bool `json:"stream"`
}
func Distribute() func(c *gin.Context) {
return func(c *gin.Context) {
var channel *model.Channel
var requestedStream bool
rejectionMessage := "No available channel for this request."
defer func() {
if c.Writer.Status() >= 400 {
service.RecordRequestPolicyTermination(c, types.NewErrorWithStatusCode(errors.New("request rejected"), types.ErrorCodeInvalidRequest, c.Writer.Status(), types.ErrOptionWithSkipRetry()))
@@ -42,7 +45,7 @@ func Distribute() func(c *gin.Context) {
other := model.NewLogOther()
other.SetPublic("status_code", c.Writer.Status())
service.AppendRelayLogAdminInfo(c, nil, other)
model.RecordErrorLog(c, c.GetInt("id"), 0, c.GetString("original_model"), c.GetString("token_name"), "No available channel for this request.", c.GetInt("token_id"), 0, false, "", other)
model.RecordErrorLog(c, c.GetInt("id"), 0, c.GetString("original_model"), c.GetString("token_name"), rejectionMessage, c.GetInt("token_id"), 0, requestedStream, "", other)
}
}
}()
@@ -57,6 +60,8 @@ func Distribute() func(c *gin.Context) {
abortWithOpenAiMessage(c, http.StatusBadRequest, i18n.T(c, i18n.MsgDistributorInvalidRequest, map[string]any{"Error": err.Error()}))
return
}
requestedStream = modelRequest.Stream || strings.Contains(c.Request.URL.Path, "streamGenerateContent") || strings.EqualFold(c.GetHeader("Upgrade"), "websocket")
c.Set("pool_request_stream", requestedStream)
_, pinned, _ := constraints.ResolvedPin()
if !pinned {
// Select a channel for the user
@@ -124,6 +129,17 @@ func Distribute() func(c *gin.Context) {
} else if selectErr.MessageID != "" {
message = i18n.T(c, selectErr.MessageID, selectErr.Params)
}
if service.RequestRoutingPolicy(c) != nil && selectErr.NoAvailableChannel {
if c.GetBool("pool_degradation_unavailable") {
message = "Group quality checks are temporarily unavailable. Please retry later."
} else if wait := c.GetInt("pool_retry_after"); wait > 0 {
message = fmt.Sprintf("No eligible group is currently available; failed groups are cooling down or being checked. Retry after %d seconds.", wait)
c.Header("Retry-After", fmt.Sprint(wait))
} else {
message = "No eligible group is available for this model under the current pool and quality settings."
}
}
rejectionMessage = message
abortWithOpenAiMessage(c, selectErr.StatusCode, message, selectErr.Code)
return
}
@@ -295,8 +311,9 @@ func getModelFromJSONBody(c *gin.Context) (*ModelRequest, error) {
c.Request.Body = io.NopCloser(storage)
return &ModelRequest{
Model: model,
Group: group,
Model: model,
Group: group,
Stream: gjson.GetBytes(requestBody, "stream").Bool(),
}, nil
}