Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
eae53ac3
authored
Jan 12, 2026
by
Seefs
Committed by
GitHub
Jan 12, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge pull request #2627 from seefs001/feature/channel-test-param-override
feat: channel testing supports parameter overriding
parent
ef572392
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
17 deletions
+66
-17
controller/channel-test.go
+22
-0
relay/common/override.go
+14
-8
relay/common/relay_info.go
+1
-0
web/src/components/table/channels/modals/EditChannelModal.jsx
+29
-9
No files found.
controller/channel-test.go
View file @
eae53ac3
...
...
@@ -193,6 +193,7 @@ func testChannel(channel *model.Channel, testModel string, endpointType string)
}
}
info
.
IsChannelTest
=
true
info
.
InitChannelMeta
(
c
)
err
=
helper
.
ModelMappedHelper
(
c
,
info
,
request
)
...
...
@@ -309,6 +310,27 @@ func testChannel(channel *model.Channel, testModel string, endpointType string)
newAPIError
:
types
.
NewError
(
err
,
types
.
ErrorCodeJsonMarshalFailed
),
}
}
//jsonData, err = relaycommon.RemoveDisabledFields(jsonData, info.ChannelOtherSettings)
//if err != nil {
// return testResult{
// context: c,
// localErr: err,
// newAPIError: types.NewError(err, types.ErrorCodeConvertRequestFailed),
// }
//}
if
len
(
info
.
ParamOverride
)
>
0
{
jsonData
,
err
=
relaycommon
.
ApplyParamOverride
(
jsonData
,
info
.
ParamOverride
,
relaycommon
.
BuildParamOverrideContext
(
info
))
if
err
!=
nil
{
return
testResult
{
context
:
c
,
localErr
:
err
,
newAPIError
:
types
.
NewError
(
err
,
types
.
ErrorCodeChannelParamOverrideInvalid
),
}
}
}
requestBody
:=
bytes
.
NewBuffer
(
jsonData
)
c
.
Request
.
Body
=
io
.
NopCloser
(
requestBody
)
resp
,
err
:=
adaptor
.
DoRequest
(
c
,
info
,
requestBody
)
...
...
relay/common/override.go
View file @
eae53ac3
...
...
@@ -570,18 +570,19 @@ func mergeObjects(jsonStr, path string, value interface{}, keepOrigin bool) (str
// BuildParamOverrideContext 提供 ApplyParamOverride 可用的上下文信息。
// 目前内置以下字段:
// - model:优先使用上游模型名(UpstreamModelName),若不存在则回落到原始模型名(OriginModelName)。
// - upstream_model:始终为通道映射后的上游模型名。
// - upstream_model/model:始终为通道映射后的上游模型名。
// - original_model:请求最初指定的模型名。
// - request_path:请求路径
// - is_channel_test:是否为渠道测试请求(同 is_test)。
func
BuildParamOverrideContext
(
info
*
RelayInfo
)
map
[
string
]
interface
{}
{
if
info
==
nil
||
info
.
ChannelMeta
==
nil
{
if
info
==
nil
{
return
nil
}
ctx
:=
make
(
map
[
string
]
interface
{})
if
info
.
UpstreamModelName
!=
""
{
ctx
[
"model"
]
=
info
.
UpstreamModelName
ctx
[
"upstream_model"
]
=
info
.
UpstreamModelName
if
info
.
ChannelMeta
!=
nil
&&
info
.
ChannelMeta
.
UpstreamModelName
!=
""
{
ctx
[
"model"
]
=
info
.
ChannelMeta
.
UpstreamModelName
ctx
[
"upstream_model"
]
=
info
.
ChannelMeta
.
UpstreamModelName
}
if
info
.
OriginModelName
!=
""
{
ctx
[
"original_model"
]
=
info
.
OriginModelName
...
...
@@ -590,8 +591,13 @@ func BuildParamOverrideContext(info *RelayInfo) map[string]interface{} {
}
}
if
len
(
ctx
)
==
0
{
return
nil
if
info
.
RequestURLPath
!=
""
{
requestPath
:=
info
.
RequestURLPath
if
requestPath
!=
""
{
ctx
[
"request_path"
]
=
requestPath
}
}
ctx
[
"is_channel_test"
]
=
info
.
IsChannelTest
return
ctx
}
relay/common/relay_info.go
View file @
eae53ac3
...
...
@@ -115,6 +115,7 @@ type RelayInfo struct {
SendResponseCount
int
FinalPreConsumedQuota
int
// 最终预消耗的配额
IsClaudeBetaQuery
bool
// /v1/messages?beta=true
IsChannelTest
bool
// channel test request
PriceData
types
.
PriceData
...
...
web/src/components/table/channels/modals/EditChannelModal.jsx
View file @
eae53ac3
...
...
@@ -199,17 +199,11 @@ const EditChannelModal = (props) => {
if
(
!
trimmed
)
return
[];
try
{
const
parsed
=
JSON
.
parse
(
trimmed
);
if
(
!
parsed
||
typeof
parsed
!==
'object'
||
Array
.
isArray
(
parsed
)
)
{
if
(
!
parsed
||
typeof
parsed
!==
'object'
||
Array
.
isArray
(
parsed
))
{
return
[];
}
const
values
=
Object
.
values
(
parsed
)
.
map
((
value
)
=>
typeof
value
===
'string'
?
value
.
trim
()
:
undefined
,
)
.
map
((
value
)
=>
(
typeof
value
===
'string'
?
value
.
trim
()
:
undefined
))
.
filter
((
value
)
=>
value
);
return
Array
.
from
(
new
Set
(
values
));
}
catch
(
error
)
{
...
...
@@ -509,6 +503,18 @@ const EditChannelModal = (props) => {
//setAutoBan
};
const
formatJsonField
=
(
fieldName
)
=>
{
const
rawValue
=
(
inputs
?.[
fieldName
]
??
''
).
trim
();
if
(
!
rawValue
)
return
;
try
{
const
parsed
=
JSON
.
parse
(
rawValue
);
handleInputChange
(
fieldName
,
JSON
.
stringify
(
parsed
,
null
,
2
));
}
catch
(
error
)
{
showError
(
`
${
t
(
'JSON格式错误'
)}
:
${
error
.
message
}
`
);
}
};
const
loadChannel
=
async
()
=>
{
setLoading
(
true
);
let
res
=
await
API
.
get
(
`/api/channel/
${
channelId
}
`
);
...
...
@@ -2812,6 +2818,12 @@ const EditChannelModal = (props) => {
>
{
t
(
'新格式模板'
)
}
</
Text
>
<
Text
className=
'!text-semi-color-primary cursor-pointer'
onClick=
{
()
=>
formatJsonField
(
'param_override'
)
}
>
{
t
(
'格式化'
)
}
</
Text
>
</
div
>
}
showClear
...
...
@@ -2852,6 +2864,12 @@ const EditChannelModal = (props) => {
>
{
t
(
'填入模板'
)
}
</
Text
>
<
Text
className=
'!text-semi-color-primary cursor-pointer'
onClick=
{
()
=>
formatJsonField
(
'header_override'
)
}
>
{
t
(
'格式化'
)
}
</
Text
>
</
div
>
<
div
>
<
Text
type=
'tertiary'
size=
'small'
>
...
...
@@ -3181,7 +3199,9 @@ const EditChannelModal = (props) => {
?
inputs
.
models
.
map
(
String
)
:
[];
const
incoming
=
modelIds
.
map
(
String
);
const
nextModels
=
Array
.
from
(
new
Set
([...
existingModels
,
...
incoming
]));
const
nextModels
=
Array
.
from
(
new
Set
([...
existingModels
,
...
incoming
]),
);
handleInputChange
(
'models'
,
nextModels
);
if
(
formApiRef
.
current
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment