Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/api_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ func ChannelType2APIType(channelType int) (int, bool) {
switch channelType {
case constant.ChannelTypeOpenAI:
apiType = constant.APITypeOpenAI
case constant.ChannelTypeQiniu:
apiType = constant.APITypeOpenAI // 七牛使用 OpenAI 兼容协议
case constant.ChannelTypeAnthropic:
apiType = constant.APITypeAnthropic
case constant.ChannelTypeBaidu:
Expand Down
3 changes: 3 additions & 0 deletions constant/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
ChannelTypeSora = 55
ChannelTypeReplicate = 56
ChannelTypeCodex = 57
ChannelTypeQiniu = 58 // 七牛 AI(OpenAI 兼容协议),默认 Base URL: https://api.qnaigc.com
ChannelTypeDummy // this one is only for count, do not add any channel after this

)
Expand Down Expand Up @@ -118,6 +119,7 @@ var ChannelBaseURLs = []string{
"https://api.openai.com", //55
"https://api.replicate.com", //56
"https://chatgpt.com", //57
"https://api.qnaigc.com", //58 - Qiniu AI gateway
}

var ChannelTypeNames = map[int]string{
Expand Down Expand Up @@ -175,6 +177,7 @@ var ChannelTypeNames = map[int]string{
ChannelTypeSora: "Sora",
ChannelTypeReplicate: "Replicate",
ChannelTypeCodex: "Codex",
ChannelTypeQiniu: "Qiniu", // 七牛 AI 网关
}

func GetChannelTypeName(channelType int) string {
Expand Down
49 changes: 49 additions & 0 deletions controller/channel_upstream_update_qiniu_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package controller

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/model"
)

// TestFetchChannelUpstreamModelIDs_Qiniu 验证七牛渠道通过 /v1/models 接口拉取上游模型列表的逻辑,
// 使用 httptest 模拟七牛 API 响应,确保请求路径、认证头和返回结果解析均正确。
func TestFetchChannelUpstreamModelIDs_Qiniu(t *testing.T) {
t.Parallel()

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Fatalf("unexpected method: %s", r.Method)
}
if r.URL.Path != "/v1/models" {
t.Fatalf("unexpected path: %s", r.URL.Path)
}
if got := r.Header.Get("Authorization"); got != "Bearer test-key" {
t.Fatalf("unexpected Authorization header: %q", got)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"object":"list","data":[{"id":"deepseek/deepseek-v3.1-terminus-thinking"},{"id":"gpt-4"}]}`))
}))
defer srv.Close()

ch := &model.Channel{
Id: 123,
Type: constant.ChannelTypeQiniu,
Key: "test-key",
Status: common.ChannelStatusEnabled,
BaseURL: common.GetPointer[string](srv.URL),
}

got, err := fetchChannelUpstreamModelIDs(ch)
if err != nil {
t.Fatalf("fetchChannelUpstreamModelIDs returned error: %v", err)
}
if len(got) != 2 || got[0] != "deepseek/deepseek-v3.1-terminus-thinking" || got[1] != "gpt-4" {
t.Fatalf("unexpected models: %#v", got)
}
}

3 changes: 2 additions & 1 deletion relay/channel/openai/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
if request == nil {
return nil, errors.New("request is nil")
}
if info.ChannelType != constant.ChannelTypeOpenAI && info.ChannelType != constant.ChannelTypeAzure {
// 仅对 streamSupportedChannels 中注册的渠道保留 StreamOptions,其余渠道置空以避免上游报错
if !info.SupportStreamOptions {
request.StreamOptions = nil
}
if info.ChannelType == constant.ChannelTypeOpenRouter {
Expand Down
1 change: 1 addition & 0 deletions relay/common/relay_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ func (info *RelayInfo) ToString() string {
// 定义支持流式选项的通道类型
var streamSupportedChannels = map[int]bool{
constant.ChannelTypeOpenAI: true,
constant.ChannelTypeQiniu: true, // 七牛支持 stream_options 参数
constant.ChannelTypeAnthropic: true,
constant.ChannelTypeAws: true,
constant.ChannelTypeGemini: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const DEPRECATED_DOUBAO_CODING_PLAN_BASE_URL = 'doubao-coding-plan';
// 支持并且已适配通过接口获取模型列表的渠道类型
const MODEL_FETCHABLE_TYPES = new Set([
1, 4, 14, 34, 17, 26, 27, 24, 47, 25, 20, 23, 31, 40, 42, 48, 43,
58, // Qiniu
]);

function type2secretPrompt(type) {
Expand Down
7 changes: 7 additions & 0 deletions web/src/constants/channel.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,18 @@ export const CHANNEL_OPTIONS = [
color: 'blue',
label: 'Codex (OpenAI OAuth)',
},
// Qiniu AI gateway — uses OpenAI-compatible protocol
{
value: 58,
color: 'green',
label: 'Qiniu',
},
];

// Channel types that support upstream model list fetching in UI.
export const MODEL_FETCHABLE_CHANNEL_TYPES = new Set([
1, 4, 14, 34, 17, 26, 27, 24, 47, 25, 20, 23, 31, 40, 42, 48, 43,
58, // Qiniu
]);

export const MODEL_TABLE_PAGE_SIZE = 10;
1 change: 1 addition & 0 deletions web/src/helpers/render.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export function getChannelIcon(channelType) {
case 1: // OpenAI
case 3: // Azure OpenAI
case 57: // Codex
case 58: // Qiniu (OpenAI compatible)
return <OpenAI size={iconSize} />;
case 2: // Midjourney Proxy
case 5: // Midjourney Proxy Plus
Expand Down