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
Unverified
Commit
70560d53
authored
Mar 29, 2026
by
Clansty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add IncludeModelName option to channel affinity rules for per-model affinity tracking
parent
fbf235d2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
5 deletions
+19
-5
service/channel_affinity.go
+17
-4
service/channel_affinity_template_test.go
+1
-1
setting/operation_setting/channel_affinity_setting.go
+1
-0
No files found.
service/channel_affinity.go
View file @
70560d53
...
...
@@ -166,12 +166,22 @@ func GetChannelAffinityCacheStats() ChannelAffinityCacheStats {
unknown
++
continue
}
if
rule
.
Include
UsingGroup
{
if
rule
.
Include
ModelName
{
if
len
(
parts
)
<
3
{
unknown
++
continue
}
}
if
rule
.
IncludeUsingGroup
{
minParts
:=
3
if
rule
.
IncludeModelName
{
minParts
=
4
}
if
len
(
parts
)
<
minParts
{
unknown
++
continue
}
}
byRuleName
[
ruleName
]
++
}
...
...
@@ -319,11 +329,14 @@ func extractChannelAffinityValue(c *gin.Context, src operation_setting.ChannelAf
}
}
func
buildChannelAffinityCacheKeySuffix
(
rule
operation_setting
.
ChannelAffinityRule
,
usingGroup
string
,
affinityValue
string
)
string
{
parts
:=
make
([]
string
,
0
,
3
)
func
buildChannelAffinityCacheKeySuffix
(
rule
operation_setting
.
ChannelAffinityRule
,
modelName
string
,
usingGroup
string
,
affinityValue
string
)
string
{
parts
:=
make
([]
string
,
0
,
4
)
if
rule
.
IncludeRuleName
&&
rule
.
Name
!=
""
{
parts
=
append
(
parts
,
rule
.
Name
)
}
if
rule
.
IncludeModelName
&&
modelName
!=
""
{
parts
=
append
(
parts
,
modelName
)
}
if
rule
.
IncludeUsingGroup
&&
usingGroup
!=
""
{
parts
=
append
(
parts
,
usingGroup
)
}
...
...
@@ -573,7 +586,7 @@ func GetPreferredChannelByAffinity(c *gin.Context, modelName string, usingGroup
if
ttlSeconds
<=
0
{
ttlSeconds
=
setting
.
DefaultTTLSeconds
}
cacheKeySuffix
:=
buildChannelAffinityCacheKeySuffix
(
rule
,
usingGroup
,
affinityValue
)
cacheKeySuffix
:=
buildChannelAffinityCacheKeySuffix
(
rule
,
modelName
,
usingGroup
,
affinityValue
)
cacheKeyFull
:=
channelAffinityCacheNamespace
+
":"
+
cacheKeySuffix
setChannelAffinityContext
(
c
,
channelAffinityMeta
{
CacheKey
:
cacheKeyFull
,
...
...
service/channel_affinity_template_test.go
View file @
70560d53
...
...
@@ -193,7 +193,7 @@ func TestChannelAffinityHitCodexTemplatePassHeadersEffective(t *testing.T) {
require
.
NotNil
(
t
,
codexRule
)
affinityValue
:=
fmt
.
Sprintf
(
"pc-hit-%d"
,
time
.
Now
()
.
UnixNano
())
cacheKeySuffix
:=
buildChannelAffinityCacheKeySuffix
(
*
codexRule
,
"default"
,
affinityValue
)
cacheKeySuffix
:=
buildChannelAffinityCacheKeySuffix
(
*
codexRule
,
"
gpt-5"
,
"
default"
,
affinityValue
)
cache
:=
getChannelAffinityCache
()
require
.
NoError
(
t
,
cache
.
SetWithTTL
(
cacheKeySuffix
,
9527
,
time
.
Minute
))
...
...
setting/operation_setting/channel_affinity_setting.go
View file @
70560d53
...
...
@@ -23,6 +23,7 @@ type ChannelAffinityRule struct {
SkipRetryOnFailure
bool
`json:"skip_retry_on_failure,omitempty"`
IncludeUsingGroup
bool
`json:"include_using_group"`
IncludeModelName
bool
`json:"include_model_name"`
IncludeRuleName
bool
`json:"include_rule_name"`
}
...
...
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