feat(custom): CNY native billing, daily check-in button, subscription plans page, usage docs and promo banner
Based on QuantumNous/new-api v1.0.0-rc.36 (shallow history squashed). - CNY quota display mode: RMB-denominated top-up and crediting across Epay/Waffo channels - New CheckinButton in both authenticated and public headers (Turnstile supported) - New /subscribe page with public plan snapshot, Alipay/balance payment, auto group upgrade/reset - New /docs 12-section beginner guide with anchor navigation - New home PromoBanner linking to /docs; i18n synced (en/zh/zh-TW/fr/ja/ru/vi) - README: document custom features, live demo https://ai.88531.cn
This commit is contained in:
commit
14a9acd368
2368 files changed
+551035
No files matched your search
@@ -0,0 +1,98 @@
|
||||
package relay
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||
"github.com/QuantumNous/new-api/relay/helper"
|
||||
"github.com/QuantumNous/new-api/relaykit/dto"
|
||||
kitreasoning "github.com/QuantumNous/new-api/relaykit/relayconvert/reasoning"
|
||||
"github.com/QuantumNous/new-api/relaykit/types"
|
||||
"github.com/QuantumNous/new-api/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOptInSafeToolLossRejectedAsBadRequestWithAdminDiagnostics(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
c, _ := gin.CreateTestContext(httptest.NewRecorder())
|
||||
c.Request = httptest.NewRequest(http.MethodPost, "/v1/chat/completions", nil)
|
||||
|
||||
info := &relaycommon.RelayInfo{
|
||||
OriginModelName: "gpt-4o",
|
||||
ChannelMeta: &relaycommon.ChannelMeta{
|
||||
UpstreamModelName: "gpt-4o",
|
||||
ChannelOtherSettings: dto.ChannelOtherSettings{
|
||||
ToolLossPolicy: string(types.ConversionLossPolicySafe),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
tools, err := common.Marshal([]map[string]any{{"codeExecution": map[string]any{}}})
|
||||
require.NoError(t, err)
|
||||
req := &dto.GeminiChatRequest{
|
||||
Contents: []dto.GeminiChatContent{
|
||||
{Role: "user", Parts: []dto.GeminiPart{{Text: "run this"}}},
|
||||
},
|
||||
Tools: tools,
|
||||
}
|
||||
|
||||
result, convErr := service.ConvertRequest(c, info, types.RelayFormatOpenAI, req)
|
||||
require.Error(t, convErr)
|
||||
var loss *types.ConversionLossError
|
||||
require.ErrorAs(t, convErr, &loss)
|
||||
require.NotEmpty(t, loss.Diagnostics)
|
||||
require.NotNil(t, result)
|
||||
|
||||
apiErr := newConvertRequestFailedError(c, info, convErr)
|
||||
require.NotNil(t, apiErr)
|
||||
assert.Equal(t, http.StatusBadRequest, apiErr.StatusCode)
|
||||
assert.Equal(t, types.ErrorCodeConvertRequestFailed, apiErr.GetErrorCode())
|
||||
assert.True(t, types.IsSkipRetryError(apiErr))
|
||||
|
||||
diagnostics := info.ConversionDiagnostics()
|
||||
require.NotEmpty(t, diagnostics)
|
||||
assert.True(t, hasHostDiagnosticCode(diagnostics, "unsupported_hosted_tool"))
|
||||
|
||||
other := service.GenerateTextOtherInfo(c, info, 1, 1, 1, 0, 0, 0, 1)
|
||||
adminInfo, ok := other.Snapshot()["admin_info"].(map[string]any)
|
||||
require.True(t, ok)
|
||||
require.Contains(t, adminInfo, "conversion_diagnostics")
|
||||
}
|
||||
|
||||
func TestUnknownModelModifierIsBadRequestWithoutRetry(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
c, _ := gin.CreateTestContext(httptest.NewRecorder())
|
||||
c.Request = httptest.NewRequest(http.MethodPost, "/v1/chat/completions", nil)
|
||||
|
||||
info := &relaycommon.RelayInfo{
|
||||
OriginModelName: "m@thinkin:on",
|
||||
ChannelMeta: &relaycommon.ChannelMeta{
|
||||
UpstreamModelName: "m@thinkin:on",
|
||||
},
|
||||
}
|
||||
err := helper.ApplyReasoningModelSuffix(c, info)
|
||||
require.Error(t, err)
|
||||
require.True(t, kitreasoning.IsClientError(err))
|
||||
assert.Contains(t, err.Error(), `unsupported model modifier "thinkin"`)
|
||||
assert.Contains(t, err.Error(), "re:")
|
||||
|
||||
apiErr := newConvertRequestFailedError(c, info, err)
|
||||
require.NotNil(t, apiErr)
|
||||
assert.Equal(t, http.StatusBadRequest, apiErr.StatusCode)
|
||||
assert.Equal(t, types.ErrorCodeConvertRequestFailed, apiErr.GetErrorCode())
|
||||
assert.True(t, types.IsSkipRetryError(apiErr))
|
||||
}
|
||||
|
||||
func hasHostDiagnosticCode(diagnostics []types.ConversionDiagnostic, code string) bool {
|
||||
for _, diagnostic := range diagnostics {
|
||||
if diagnostic.Code == code {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user