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
2cbedaf6
authored
May 07, 2025
by
joey
Committed by
GitHub
May 07, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support model mapping chain
#1033
parent
910e058c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
3 deletions
+32
-3
relay/helper/model_mapped.go
+32
-3
No files found.
relay/helper/model_mapped.go
View file @
2cbedaf6
...
...
@@ -2,9 +2,11 @@ package helper
import
(
"encoding/json"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"one-api/relay/common"
"github.com/gin-gonic/gin"
)
func
ModelMappedHelper
(
c
*
gin
.
Context
,
info
*
common
.
RelayInfo
)
error
{
...
...
@@ -16,9 +18,36 @@ func ModelMappedHelper(c *gin.Context, info *common.RelayInfo) error {
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unmarshal_model_mapping_failed"
)
}
if
modelMap
[
info
.
OriginModelName
]
!=
""
{
info
.
UpstreamModelName
=
modelMap
[
info
.
OriginModelName
]
// 支持链式模型重定向,最终使用链尾的模型
currentModel
:=
info
.
OriginModelName
visitedModels
:=
map
[
string
]
bool
{
currentModel
:
true
,
}
for
{
if
mappedModel
,
exists
:=
modelMap
[
currentModel
];
exists
&&
mappedModel
!=
""
{
// 模型重定向循环检测,避免无限循环
if
visitedModels
[
mappedModel
]
{
if
mappedModel
==
currentModel
{
if
currentModel
==
info
.
OriginModelName
{
info
.
IsModelMapped
=
false
return
nil
}
else
{
info
.
IsModelMapped
=
true
break
}
}
return
errors
.
New
(
"model_mapping_contains_cycle"
)
}
visitedModels
[
mappedModel
]
=
true
currentModel
=
mappedModel
info
.
IsModelMapped
=
true
}
else
{
break
}
}
if
info
.
IsModelMapped
{
info
.
UpstreamModelName
=
currentModel
}
}
return
nil
...
...
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