mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 06:30:21 +00:00
feat(relay): hosted-tool conversion fidelity, reasoning normalization, and billing usage integrity (#7137)
* feat(relaykit): preserve hosted tools across conversions - add protocol-neutral hosted-tool DTOs, conversion metadata, and loss policies - bridge citations, grounding metadata, and hosted-tool stream lifecycles - document the public conversion behavior and channel policy controls * refactor(relaykit): normalize reasoning and thinking intent - centralize provider-neutral reasoning intent, effort, and budget mappings - parse model suffixes at the host entry boundary while preserving provider-owned tails - keep adaptive Claude thinking and explicit zero-token compatibility consistent * fix(billing): preserve authoritative usage across relay hops - carry native BillingUsage sidecars through direct and streamed protocol bridges - merge partial and terminal usage monotonically with safe fallback settlement - retain cache metadata, penultimate usage, and per-call Gemini tool surcharges * feat(relay): bridge Responses with Claude and Gemini protocols - add direct request, response, and stream converters across supported relay formats - expose Claude count_tokens and Chat-to-Responses compatibility endpoints - carry conversion diagnostics through the host while retaining the curated public goldens * fix(relay): wire relaykit conversions into host channels - connect handlers, adaptors, and channel settings to the standalone conversion layer - keep model mapping, pricing identity, retries, and provider-specific suffix behavior aligned - ignore local audit artifacts and retain focused public regression coverage
This commit is contained in:
@@ -35,6 +35,7 @@ func (p ChatCompletionsToResponsesPolicy) IsChannelEnabled(channelID int, channe
|
||||
type GlobalSettings struct {
|
||||
PassThroughRequestEnabled bool `json:"pass_through_request_enabled"`
|
||||
ThinkingModelBlacklist []string `json:"thinking_model_blacklist"`
|
||||
EffortTailModelIDs []string `json:"effort_tail_model_ids"`
|
||||
ChatCompletionsToResponsesPolicy ChatCompletionsToResponsesPolicy `json:"chat_completions_to_responses_policy"`
|
||||
}
|
||||
|
||||
@@ -45,6 +46,13 @@ var defaultOpenaiSettings = GlobalSettings{
|
||||
"moonshotai/kimi-k2-thinking",
|
||||
"kimi-k2-thinking",
|
||||
},
|
||||
EffortTailModelIDs: []string{
|
||||
"gpt-5.1-codex-max",
|
||||
"qwen-image-edit-max",
|
||||
"qwen-max",
|
||||
"stable-diffusion-3-medium",
|
||||
"yi-medium",
|
||||
},
|
||||
ChatCompletionsToResponsesPolicy: ChatCompletionsToResponsesPolicy{
|
||||
Enabled: false,
|
||||
AllChannels: true,
|
||||
@@ -77,3 +85,26 @@ func ShouldPreserveThinkingSuffix(modelName string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ShouldPreserveEffortTail reports model IDs whose names already end in an
|
||||
// effort-like token and must not be treated as reasoning aliases.
|
||||
func ShouldPreserveEffortTail(modelName string) bool {
|
||||
target := strings.TrimSpace(modelName)
|
||||
if target == "" {
|
||||
return false
|
||||
}
|
||||
bare := target
|
||||
if slash := strings.LastIndex(bare, "/"); slash >= 0 {
|
||||
bare = bare[slash+1:]
|
||||
}
|
||||
for _, entry := range globalSettings.EffortTailModelIDs {
|
||||
entry = strings.TrimSpace(entry)
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
if entry == target || entry == bare {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -179,12 +179,10 @@ var defaultModelRatio = map[string]float64{
|
||||
"gemini-2.5-pro-exp-03-25": 0.625,
|
||||
"gemini-2.5-pro-preview-03-25": 0.625,
|
||||
"gemini-2.5-pro": 0.625,
|
||||
"gemini-2.5-flash-preview-04-17": 0.075,
|
||||
"gemini-2.5-flash-preview-04-17-thinking": 0.075,
|
||||
"gemini-2.5-flash-preview-04-17-nothinking": 0.075,
|
||||
"gemini-2.5-flash-preview-05-20": 0.075,
|
||||
"gemini-2.5-flash-preview-05-20-thinking": 0.075,
|
||||
"gemini-2.5-flash-preview-05-20-nothinking": 0.075,
|
||||
"gemini-2.5-flash-preview-04-17": 0.075,
|
||||
"gemini-2.5-flash-preview-04-17-thinking": 0.075,
|
||||
"gemini-2.5-flash-preview-05-20": 0.075,
|
||||
"gemini-2.5-flash-preview-05-20-thinking": 0.075,
|
||||
"gemini-2.5-flash-thinking-*": 0.075, // 用于为后续所有2.5 flash thinking budget 模型设置默认倍率
|
||||
"gemini-2.5-pro-thinking-*": 0.625, // 用于为后续所有2.5 pro thinking budget 模型设置默认倍率
|
||||
"gemini-2.5-flash-lite-preview-thinking-*": 0.05,
|
||||
@@ -549,9 +547,6 @@ func getHardcodedCompletionModelRatio(name string) (float64, bool) {
|
||||
return 8, false
|
||||
} else if strings.HasPrefix(name, "gemini-2.5-flash") { // 处理不同的flash模型倍率
|
||||
if strings.HasPrefix(name, "gemini-2.5-flash-preview") {
|
||||
if strings.HasSuffix(name, "-nothinking") {
|
||||
return 4, false
|
||||
}
|
||||
return 3.5 / 0.15, false
|
||||
}
|
||||
if strings.HasPrefix(name, "gemini-2.5-flash-lite") {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
// Package reasoning re-exports the pure model-name effort-suffix helpers,
|
||||
// which moved to the conversion kit (service/relayconvert/reasoning) as part
|
||||
// which moved to the conversion kit (relaykit/relayconvert/reasoning) as part
|
||||
// of the relaykit extraction. Host code keeps importing this path unchanged.
|
||||
package reasoning
|
||||
|
||||
import kitreasoning "github.com/QuantumNous/new-api/relaykit/relayconvert/reasoning"
|
||||
import (
|
||||
kitreasoning "github.com/QuantumNous/new-api/relaykit/relayconvert/reasoning"
|
||||
"github.com/QuantumNous/new-api/setting/model_setting"
|
||||
)
|
||||
|
||||
var (
|
||||
EffortSuffixes = kitreasoning.EffortSuffixes
|
||||
@@ -12,8 +15,13 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
TrimEffortSuffix = kitreasoning.TrimEffortSuffix
|
||||
TrimEffortSuffixWithSuffixes = kitreasoning.TrimEffortSuffixWithSuffixes
|
||||
ParseOpenAIReasoningEffortFromModelSuffix = kitreasoning.ParseOpenAIReasoningEffortFromModelSuffix
|
||||
ParseDeepSeekV4ThinkingSuffix = kitreasoning.ParseDeepSeekV4ThinkingSuffix
|
||||
TrimEffortSuffixWithSuffixes = kitreasoning.TrimEffortSuffixWithSuffixes
|
||||
ParseDeepSeekV4ThinkingSuffix = kitreasoning.ParseDeepSeekV4ThinkingSuffix
|
||||
TrimGeminiThinkingSuffix = kitreasoning.TrimGeminiThinkingSuffix
|
||||
)
|
||||
|
||||
// ParseOpenAIReasoningEffortFromModelSuffix applies the host effort-tail
|
||||
// whitelist so real model IDs such as qwen-max are not treated as aliases.
|
||||
func ParseOpenAIReasoningEffortFromModelSuffix(modelName string) (string, string) {
|
||||
return kitreasoning.ParseOpenAIReasoningEffortFromModelSuffix(modelName, model_setting.ShouldPreserveEffortTail)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user