mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 14:41:21 +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
141 lines
3.9 KiB
Go
141 lines
3.9 KiB
Go
package reasoning
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestParseGeminiModelSuffixNoThinkingDisablesReasoning(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
base, intent, found, err := ParseGeminiModelSuffix("gemini-2.5-flash-nothinking", true)
|
|
require.NoError(t, err)
|
|
require.True(t, found)
|
|
assert.Equal(t, "gemini-2.5-flash", base)
|
|
assert.Equal(t, ModeDisabled, intent.Mode)
|
|
assert.Equal(t, EffortNone, intent.Effort)
|
|
assert.Equal(t, SourceSuffix, intent.Source)
|
|
}
|
|
|
|
func TestParseKnownProviderModelSuffix(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
preserveQwenMax := func(name string) bool { return name == "qwen-max" || name == "vendor/qwen-max" }
|
|
|
|
tests := []struct {
|
|
name string
|
|
model string
|
|
allowThinkingAlias bool
|
|
wantBase string
|
|
wantFound bool
|
|
wantMode Mode
|
|
wantEffort Effort
|
|
wantBudget *int
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "claude thinking alias",
|
|
model: "claude-3-7-sonnet-thinking",
|
|
allowThinkingAlias: true,
|
|
wantBase: "claude-3-7-sonnet",
|
|
wantFound: true,
|
|
wantMode: ModeEnabled,
|
|
},
|
|
{
|
|
name: "claude nothinking alias",
|
|
model: "claude-3-7-sonnet-nothinking",
|
|
allowThinkingAlias: true,
|
|
wantBase: "claude-3-7-sonnet",
|
|
wantFound: true,
|
|
wantMode: ModeDisabled,
|
|
wantEffort: EffortNone,
|
|
},
|
|
{
|
|
name: "claude thinking budget",
|
|
model: "claude-3-7-sonnet-thinking-8192",
|
|
allowThinkingAlias: true,
|
|
wantBase: "claude-3-7-sonnet",
|
|
wantFound: true,
|
|
wantBudget: intPtr(8192),
|
|
},
|
|
{
|
|
name: "claude effort tail",
|
|
model: "claude-opus-4-8-high",
|
|
allowThinkingAlias: true,
|
|
wantBase: "claude-opus-4-8",
|
|
wantFound: true,
|
|
wantMode: ModeEnabled,
|
|
wantEffort: EffortHigh,
|
|
},
|
|
{
|
|
name: "gemini thinking alias",
|
|
model: "gemini-2.5-flash-thinking",
|
|
allowThinkingAlias: true,
|
|
wantBase: "gemini-2.5-flash",
|
|
wantFound: true,
|
|
wantMode: ModeEnabled,
|
|
},
|
|
{
|
|
name: "malformed thinking budget",
|
|
model: "claude-3-7-sonnet-thinking-abc",
|
|
allowThinkingAlias: true,
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "unknown openai-compatible name is untouched",
|
|
model: "gpt-4o-mini",
|
|
wantBase: "gpt-4o-mini",
|
|
wantFound: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
base, intent, found, err := ParseKnownProviderModelSuffix(tt.model, tt.allowThinkingAlias)
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
assert.Equal(t, tt.wantFound, found)
|
|
assert.Equal(t, tt.wantBase, base)
|
|
assert.Equal(t, tt.wantMode, intent.Mode)
|
|
assert.Equal(t, tt.wantEffort, intent.Effort)
|
|
if tt.wantBudget != nil {
|
|
require.NotNil(t, intent.BudgetTokens)
|
|
assert.Equal(t, *tt.wantBudget, *intent.BudgetTokens)
|
|
} else {
|
|
assert.Nil(t, intent.BudgetTokens)
|
|
}
|
|
})
|
|
}
|
|
|
|
t.Run("openai effort tail", func(t *testing.T) {
|
|
t.Parallel()
|
|
effort, base := ParseOpenAIReasoningEffortFromModelSuffix("gpt-5.6-sol-high", nil)
|
|
assert.Equal(t, "high", effort)
|
|
assert.Equal(t, "gpt-5.6-sol", base)
|
|
})
|
|
|
|
t.Run("preserve effort tail on real model id", func(t *testing.T) {
|
|
t.Parallel()
|
|
effort, base := ParseOpenAIReasoningEffortFromModelSuffix("qwen-max", preserveQwenMax)
|
|
assert.Empty(t, effort)
|
|
assert.Equal(t, "qwen-max", base)
|
|
})
|
|
|
|
t.Run("preserve effort tail with vendor prefix", func(t *testing.T) {
|
|
t.Parallel()
|
|
effort, base := ParseOpenAIReasoningEffortFromModelSuffix("vendor/qwen-max", preserveQwenMax)
|
|
assert.Empty(t, effort)
|
|
assert.Equal(t, "vendor/qwen-max", base)
|
|
})
|
|
}
|
|
|
|
func intPtr(v int) *int {
|
|
return &v
|
|
}
|