Skip to content

Commit 865be3c

Browse files
committed
fix: qianfan SupportMode
1 parent 159a7f6 commit 865be3c

42 files changed

Lines changed: 289 additions & 73 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/controller/channel-test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func testSingleModel(
8282
return nil, errors.New("adaptor not found")
8383
}
8484

85-
if !a.SupportMode(modelConfig.Type) {
85+
if !a.SupportMode(meta.NewMeta(channel, modelConfig.Type, modelName, modelConfig)) {
8686
return nil, fmt.Errorf("%s not supported by adaptor", modelConfig.Type)
8787
}
8888
}

core/controller/relay-channel.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
"github.com/labring/aiproxy/core/middleware"
1414
"github.com/labring/aiproxy/core/model"
1515
"github.com/labring/aiproxy/core/monitor"
16+
"github.com/labring/aiproxy/core/relay/adaptor"
1617
"github.com/labring/aiproxy/core/relay/adaptors"
18+
relaymeta "github.com/labring/aiproxy/core/relay/meta"
1719
"github.com/labring/aiproxy/core/relay/mode"
1820
"github.com/labring/aiproxy/core/relay/plugin/cachefollow"
1921
)
@@ -32,6 +34,30 @@ const (
3234
errorRatePenalty = 2.0
3335
)
3436

37+
func supportModeMeta(
38+
mc *model.ModelCaches,
39+
channel *model.Channel,
40+
modelName string,
41+
m mode.Mode,
42+
) *relaymeta.Meta {
43+
modelConfig := model.ModelConfig{}
44+
if mc != nil && mc.ModelConfig != nil {
45+
modelConfig, _ = mc.ModelConfig.GetModelConfig(modelName)
46+
}
47+
48+
return relaymeta.NewMeta(channel, m, modelName, modelConfig)
49+
}
50+
51+
func adaptorSupportsMode(
52+
a adaptor.Adaptor,
53+
mc *model.ModelCaches,
54+
channel *model.Channel,
55+
modelName string,
56+
m mode.Mode,
57+
) bool {
58+
return a.SupportMode(supportModeMeta(mc, channel, modelName, m))
59+
}
60+
3561
func GetChannelFromHeader(
3662
header string,
3763
mc *model.ModelCaches,
@@ -54,7 +80,7 @@ func GetChannelFromHeader(
5480
return nil, fmt.Errorf("adaptor not found for channel %d", channel.ID)
5581
}
5682

57-
if !a.SupportMode(m) {
83+
if !adaptorSupportsMode(a, mc, channel, model, m) {
5884
return nil, fmt.Errorf("channel %d not supported by adaptor", channel.ID)
5985
}
6086

@@ -72,7 +98,7 @@ func GetChannelFromHeader(
7298
return nil, fmt.Errorf("adaptor not found for channel %d", channel.ID)
7399
}
74100

75-
if !a.SupportMode(m) {
101+
if !adaptorSupportsMode(a, mc, channel, model, m) {
76102
return nil, fmt.Errorf("channel %d not supported by adaptor", channel.ID)
77103
}
78104

@@ -127,7 +153,7 @@ func GetChannelFromRequest(
127153
)
128154
}
129155

130-
if !a.SupportMode(m) {
156+
if !adaptorSupportsMode(a, mc, channel, modelName, m) {
131157
return nil, fmt.Errorf(
132158
"pinned channel %d not supported by adaptor",
133159
channel.ID,
@@ -164,7 +190,7 @@ func getAvailableChannels(
164190
continue
165191
}
166192

167-
if !a.SupportMode(mode) {
193+
if !adaptorSupportsMode(a, mc, channel, modelName, mode) {
168194
continue
169195
}
170196

@@ -179,7 +205,7 @@ func getAvailableChannels(
179205
continue
180206
}
181207

182-
if !a.SupportMode(mode) {
208+
if !adaptorSupportsMode(a, mc, channel, modelName, mode) {
183209
continue
184210
}
185211

core/relay/adaptor/ali/adaptor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ func (a *Adaptor) DefaultBaseURL() string {
3131
return baseURL
3232
}
3333

34-
func (a *Adaptor) SupportMode(m mode.Mode) bool {
34+
func (a *Adaptor) SupportMode(mt *meta.Meta) bool {
35+
m := adaptor.ModeFromMeta(mt)
36+
3537
return m == mode.ChatCompletions ||
3638
m == mode.Completions ||
3739
m == mode.Embeddings ||

core/relay/adaptor/ali/adaptor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestAdaptorSupportModeResponses(t *testing.T) {
2828
mode.ResponsesInputItems,
2929
}
3030
for _, m := range supportedModes {
31-
if !adaptor.SupportMode(m) {
31+
if !adaptor.SupportMode(&meta.Meta{Mode: m}) {
3232
t.Fatalf("expected mode %s to be supported", m)
3333
}
3434
}

core/relay/adaptor/anthropic/adaptor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ func (a *Adaptor) DefaultBaseURL() string {
3434
return baseURL
3535
}
3636

37-
func (a *Adaptor) SupportMode(m mode.Mode) bool {
37+
func (a *Adaptor) SupportMode(mt *meta.Meta) bool {
38+
m := adaptor.ModeFromMeta(mt)
39+
3840
return m == mode.ChatCompletions ||
3941
m == mode.Anthropic ||
4042
m == mode.Gemini

core/relay/adaptor/antling/adaptor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func (a *Adaptor) DefaultBaseURL() string {
3737
return baseURL
3838
}
3939

40-
func (a *Adaptor) SupportMode(m mode.Mode) bool {
40+
func (a *Adaptor) SupportMode(mt *meta.Meta) bool {
41+
m := adaptor.ModeFromMeta(mt)
42+
4143
return m == mode.ChatCompletions ||
4244
m == mode.Anthropic ||
4345
m == mode.Gemini

core/relay/adaptor/antling/adaptor_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ func TestAntLingAdaptorMetadata(t *testing.T) {
3333
func TestAntLingAdaptorSupportMode(t *testing.T) {
3434
a := &antling.Adaptor{}
3535

36-
assert.True(t, a.SupportMode(mode.ChatCompletions))
37-
assert.True(t, a.SupportMode(mode.Anthropic))
38-
assert.True(t, a.SupportMode(mode.Gemini))
39-
assert.False(t, a.SupportMode(mode.Completions))
40-
assert.False(t, a.SupportMode(mode.Embeddings))
41-
assert.False(t, a.SupportMode(mode.Responses))
36+
assert.True(t, a.SupportMode(&meta.Meta{Mode: mode.ChatCompletions}))
37+
assert.True(t, a.SupportMode(&meta.Meta{Mode: mode.Anthropic}))
38+
assert.True(t, a.SupportMode(&meta.Meta{Mode: mode.Gemini}))
39+
assert.False(t, a.SupportMode(&meta.Meta{Mode: mode.Completions}))
40+
assert.False(t, a.SupportMode(&meta.Meta{Mode: mode.Embeddings}))
41+
assert.False(t, a.SupportMode(&meta.Meta{Mode: mode.Responses}))
4242
}
4343

4444
func TestAntLingGetRequestURLAnthropic(t *testing.T) {

core/relay/adaptor/aws/adaptor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ func (a *Adaptor) DefaultBaseURL() string {
2525
return ""
2626
}
2727

28-
func (a *Adaptor) SupportMode(m mode.Mode) bool {
28+
func (a *Adaptor) SupportMode(mt *meta.Meta) bool {
29+
m := adaptor.ModeFromMeta(mt)
30+
2931
return m == mode.ChatCompletions ||
3032
m == mode.Completions ||
3133
m == mode.Anthropic ||

core/relay/adaptor/baidu/adaptor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func (a *Adaptor) DefaultBaseURL() string {
3232
return baseURL
3333
}
3434

35-
func (a *Adaptor) SupportMode(m mode.Mode) bool {
35+
func (a *Adaptor) SupportMode(mt *meta.Meta) bool {
36+
m := adaptor.ModeFromMeta(mt)
37+
3638
return m == mode.ChatCompletions ||
3739
m == mode.Embeddings ||
3840
m == mode.Rerank ||

core/relay/adaptor/baiduv2/adaptor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func (a *Adaptor) DefaultBaseURL() string {
3232
return baseURL
3333
}
3434

35-
func (a *Adaptor) SupportMode(m mode.Mode) bool {
35+
func (a *Adaptor) SupportMode(mt *meta.Meta) bool {
36+
m := adaptor.ModeFromMeta(mt)
37+
3638
return m == mode.ChatCompletions ||
3739
m == mode.Anthropic ||
3840
m == mode.Gemini ||

0 commit comments

Comments
 (0)