mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 14:41:21 +00:00
feat: enhance text protocol conversion and advanced custom routing (#5825)
* refactor: consolidate relay protocol converters * refactor relayconvert text converters * feat: refine relay converters and advanced custom routing * refactor: enhance logging and add thought signature handling for Gemini requests * refactor: enhance channel cache and pricing endpoint handling for advanced custom models * feat: preserve billing usage semantics * feat: add protocol-aware billing usage * Delete useless files * chore: update action versions in workflow files * chore: update Docker action versions in workflow files * fix: harden billing usage settlement and hot-path route matching - estimate Gemini completion tokens locally when billable usageMetadata is prompt-only but output content was received (e.g. client aborts the stream before the final chunk), and rebuild the attached billing_usage as estimated so settlement does not bill zero output tokens - guard NewClaudeMessagesBillingUsage against all-zero ClaudeUsage, matching the OpenAI/Gemini constructors, so a zero billing_usage cannot override a non-zero top-level usage during settlement - cache compiled advanced-custom route model regexes; they run on the request hot path and were recompiled per request - move the effectiveBillingUsage remap to PostTextConsumeQuota only, and document that calculateTextQuotaSummary expects remapped usage - document the updatePricingLock -> channelSyncLock lock ordering that InitChannelCache/CacheUpdateChannel rely on, and the aux-struct pitfall in GeminiChatResponse.UnmarshalJSON
This commit is contained in:
@@ -105,7 +105,7 @@ func Distribute() func(c *gin.Context) {
|
||||
affinityUsable := false
|
||||
preferred, err := model.CacheGetChannel(preferredChannelID)
|
||||
if err == nil && preferred != nil && preferred.Status == common.ChannelStatusEnabled &&
|
||||
channelSupportsRequestPath(preferred, c.Request.URL.Path) {
|
||||
channelSupportsRequestPath(preferred, c.Request.URL.Path, modelRequest.Model) {
|
||||
if usingGroup == "auto" {
|
||||
userGroup := common.GetContextKeyString(c, constant.ContextKeyUserGroup)
|
||||
autoGroups := service.GetUserAutoGroup(userGroup)
|
||||
@@ -172,7 +172,7 @@ func Distribute() func(c *gin.Context) {
|
||||
// channelSupportsRequestPath reports whether a channel can serve the request path.
|
||||
// Only Advanced Custom (type 58) channels are path-checked; all other channel types
|
||||
// always pass. A type-58 channel is usable only when one of its routes matches.
|
||||
func channelSupportsRequestPath(channel *model.Channel, requestPath string) bool {
|
||||
func channelSupportsRequestPath(channel *model.Channel, requestPath string, requestModel string) bool {
|
||||
if channel == nil {
|
||||
return false
|
||||
}
|
||||
@@ -180,7 +180,7 @@ func channelSupportsRequestPath(channel *model.Channel, requestPath string) bool
|
||||
return true
|
||||
}
|
||||
config := channel.GetOtherSettings().AdvancedCustom
|
||||
return config != nil && config.SupportsPath(requestPath)
|
||||
return config != nil && config.SupportsPathForModel(requestPath, requestModel)
|
||||
}
|
||||
|
||||
// getModelFromRequest 从请求中读取模型信息
|
||||
|
||||
Reference in New Issue
Block a user