mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 22:49:57 +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
86 lines
2.6 KiB
Go
86 lines
2.6 KiB
Go
package sub2api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/QuantumNous/new-api/constant"
|
|
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
|
relayconstant "github.com/QuantumNous/new-api/relay/constant"
|
|
"github.com/QuantumNous/new-api/relaykit/dto"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetRequestURLAlphaSearch(t *testing.T) {
|
|
adaptor := &Adaptor{}
|
|
info := &relaycommon.RelayInfo{
|
|
ChannelMeta: &relaycommon.ChannelMeta{
|
|
ChannelType: constant.ChannelTypeSub2API,
|
|
ChannelBaseUrl: "https://sub2api.example",
|
|
},
|
|
RequestURLPath: "/v1/alpha/search",
|
|
RelayMode: relayconstant.RelayModeAlphaSearch,
|
|
}
|
|
|
|
url, err := adaptor.GetRequestURL(info)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "https://sub2api.example/v1/alpha/search", url)
|
|
}
|
|
|
|
func TestAdaptorInheritsNewAPIResponsesCompactSupport(t *testing.T) {
|
|
adaptor := &Adaptor{}
|
|
info := &relaycommon.RelayInfo{
|
|
ChannelMeta: &relaycommon.ChannelMeta{
|
|
ChannelType: constant.ChannelTypeSub2API,
|
|
ChannelBaseUrl: "https://sub2api.example",
|
|
},
|
|
RequestURLPath: "/v1/responses/compact",
|
|
RelayMode: relayconstant.RelayModeResponsesCompact,
|
|
}
|
|
|
|
url, err := adaptor.GetRequestURL(info)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "https://sub2api.example/v1/responses/compact", url)
|
|
assert.Equal(t, "sub2api", adaptor.GetChannelName())
|
|
assert.Empty(t, adaptor.GetModelList())
|
|
}
|
|
|
|
func TestConvertClaudeRequestPreservesAdaptiveThinkingForCompatibleModel(t *testing.T) {
|
|
adaptor := &Adaptor{}
|
|
maxTokens := uint(8192)
|
|
temperature := 0.2
|
|
topP := 0.99
|
|
request := &dto.ClaudeRequest{
|
|
Model: "gpt-5.6-sol",
|
|
MaxTokens: &maxTokens,
|
|
Temperature: &temperature,
|
|
TopP: &topP,
|
|
Thinking: &dto.Thinking{Type: "adaptive", Display: "summarized"},
|
|
OutputConfig: json.RawMessage(`{"effort":"xhigh","provider_option":true}`),
|
|
Messages: []dto.ClaudeMessage{
|
|
{Role: "user", Content: "hello"},
|
|
},
|
|
}
|
|
info := &relaycommon.RelayInfo{
|
|
OriginModelName: "gpt-5.6-sol",
|
|
ChannelMeta: &relaycommon.ChannelMeta{
|
|
ChannelType: constant.ChannelTypeSub2API,
|
|
},
|
|
}
|
|
|
|
converted, err := adaptor.ConvertClaudeRequest(nil, info, request)
|
|
|
|
require.NoError(t, err)
|
|
assert.Same(t, request, converted)
|
|
require.NotNil(t, request.Thinking)
|
|
assert.Equal(t, "adaptive", request.Thinking.Type)
|
|
assert.Equal(t, "summarized", request.Thinking.Display)
|
|
assert.JSONEq(t, `{"effort":"xhigh","provider_option":true}`, string(request.OutputConfig))
|
|
assert.Same(t, &temperature, request.Temperature)
|
|
assert.Same(t, &topP, request.TopP)
|
|
assert.Equal(t, "xhigh", info.ReasoningEffort)
|
|
assert.Equal(t, "gpt-5.6-sol", info.UpstreamModelName)
|
|
}
|