feat: 算力引擎 Go 后端核心(new-api)
- 统一 OpenAI 兼容 /v1 中继 + 渠道/额度/令牌/流水 - 各领域包:relay 模型网关、model 数据层、controller 管理 API
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package sub2api
|
||||
|
||||
import (
|
||||
"github.com/QuantumNous/new-api/relay/channel/newapi"
|
||||
)
|
||||
|
||||
type Adaptor struct {
|
||||
newapi.Adaptor
|
||||
}
|
||||
|
||||
func (a *Adaptor) GetModelList() []string {
|
||||
return ModelList
|
||||
}
|
||||
|
||||
func (a *Adaptor) GetChannelName() string {
|
||||
return ChannelName
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package sub2api
|
||||
|
||||
import (
|
||||
"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/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())
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package sub2api
|
||||
|
||||
const ChannelName = "sub2api"
|
||||
|
||||
// ModelList is empty because models are fetched dynamically from upstream /v1/models.
|
||||
var ModelList = []string{}
|
||||
Reference in New Issue
Block a user