mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-07 18:18:00 +00:00
* 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
111 lines
2.9 KiB
Go
111 lines
2.9 KiB
Go
package model_setting
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/QuantumNous/new-api/setting/config"
|
|
)
|
|
|
|
type ChatCompletionsToResponsesPolicy struct {
|
|
Enabled bool `json:"enabled"`
|
|
AllChannels bool `json:"all_channels"`
|
|
ChannelIDs []int `json:"channel_ids,omitempty"`
|
|
ChannelTypes []int `json:"channel_types,omitempty"`
|
|
ModelPatterns []string `json:"model_patterns,omitempty"`
|
|
}
|
|
|
|
func (p ChatCompletionsToResponsesPolicy) IsChannelEnabled(channelID int, channelType int) bool {
|
|
if !p.Enabled {
|
|
return false
|
|
}
|
|
if p.AllChannels {
|
|
return true
|
|
}
|
|
|
|
if channelID > 0 && len(p.ChannelIDs) > 0 && slices.Contains(p.ChannelIDs, channelID) {
|
|
return true
|
|
}
|
|
if channelType > 0 && len(p.ChannelTypes) > 0 && slices.Contains(p.ChannelTypes, channelType) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
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"`
|
|
}
|
|
|
|
// 默认配置
|
|
var defaultOpenaiSettings = GlobalSettings{
|
|
PassThroughRequestEnabled: false,
|
|
ThinkingModelBlacklist: []string{
|
|
"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,
|
|
},
|
|
}
|
|
|
|
// 全局实例
|
|
var globalSettings = defaultOpenaiSettings
|
|
|
|
func init() {
|
|
// 注册到全局配置管理器
|
|
config.GlobalConfig.Register("global", &globalSettings)
|
|
}
|
|
|
|
func GetGlobalSettings() *GlobalSettings {
|
|
return &globalSettings
|
|
}
|
|
|
|
// ShouldPreserveThinkingSuffix 判断模型是否配置为保留 thinking/-nothinking/-low/-high/-medium 后缀
|
|
func ShouldPreserveThinkingSuffix(modelName string) bool {
|
|
target := strings.TrimSpace(modelName)
|
|
if target == "" {
|
|
return false
|
|
}
|
|
|
|
for _, entry := range globalSettings.ThinkingModelBlacklist {
|
|
if strings.TrimSpace(entry) == target {
|
|
return true
|
|
}
|
|
}
|
|
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
|
|
}
|