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
7ebe52ea
authored
Sep 18, 2024
by
GuoRuqiang
Committed by
GitHub
Sep 18, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'Calcium-Ion:main' into main
parents
68ef8491
077f9807
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
11 deletions
+24
-11
common/model-ratio.go
+3
-0
controller/model.go
+15
-10
middleware/distributor.go
+6
-1
No files found.
common/model-ratio.go
View file @
7ebe52ea
...
@@ -375,6 +375,9 @@ func GetCompletionRatio(name string) float64 {
...
@@ -375,6 +375,9 @@ func GetCompletionRatio(name string) float64 {
return
3
return
3
}
}
if
strings
.
HasPrefix
(
name
,
"gemini-"
)
{
if
strings
.
HasPrefix
(
name
,
"gemini-"
)
{
if
strings
.
Contains
(
name
,
"flash"
)
{
return
4
}
return
3
return
3
}
}
if
strings
.
HasPrefix
(
name
,
"command"
)
{
if
strings
.
HasPrefix
(
name
,
"command"
)
{
...
...
controller/model.go
View file @
7ebe52ea
...
@@ -137,15 +137,6 @@ func init() {
...
@@ -137,15 +137,6 @@ func init() {
}
}
func
ListModels
(
c
*
gin
.
Context
)
{
func
ListModels
(
c
*
gin
.
Context
)
{
userId
:=
c
.
GetInt
(
"id"
)
user
,
err
:=
model
.
GetUserById
(
userId
,
true
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
}
userOpenAiModels
:=
make
([]
dto
.
OpenAIModels
,
0
)
userOpenAiModels
:=
make
([]
dto
.
OpenAIModels
,
0
)
permission
:=
getPermission
()
permission
:=
getPermission
()
...
@@ -174,7 +165,21 @@ func ListModels(c *gin.Context) {
...
@@ -174,7 +165,21 @@ func ListModels(c *gin.Context) {
}
}
}
}
}
else
{
}
else
{
models
:=
model
.
GetGroupModels
(
user
.
Group
)
userId
:=
c
.
GetInt
(
"id"
)
userGroup
,
err
:=
model
.
GetUserGroup
(
userId
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"get user group failed"
,
})
return
}
group
:=
userGroup
tokenGroup
:=
c
.
GetString
(
"token_group"
)
if
tokenGroup
!=
""
{
group
=
tokenGroup
}
models
:=
model
.
GetGroupModels
(
group
)
for
_
,
s
:=
range
models
{
for
_
,
s
:=
range
models
{
if
_
,
ok
:=
openAIModelsMap
[
s
];
ok
{
if
_
,
ok
:=
openAIModelsMap
[
s
];
ok
{
userOpenAiModels
=
append
(
userOpenAiModels
,
openAIModelsMap
[
s
])
userOpenAiModels
=
append
(
userOpenAiModels
,
openAIModelsMap
[
s
])
...
...
middleware/distributor.go
View file @
7ebe52ea
...
@@ -41,9 +41,14 @@ func Distribute() func(c *gin.Context) {
...
@@ -41,9 +41,14 @@ func Distribute() func(c *gin.Context) {
userGroup
,
_
:=
model
.
CacheGetUserGroup
(
userId
)
userGroup
,
_
:=
model
.
CacheGetUserGroup
(
userId
)
tokenGroup
:=
c
.
GetString
(
"token_group"
)
tokenGroup
:=
c
.
GetString
(
"token_group"
)
if
tokenGroup
!=
""
{
if
tokenGroup
!=
""
{
// check common.UserUsableGroups[userGroup]
if
_
,
ok
:=
common
.
UserUsableGroups
[
tokenGroup
];
!
ok
{
abortWithOpenAiMessage
(
c
,
http
.
StatusForbidden
,
fmt
.
Sprintf
(
"令牌分组 %s 已被禁用"
,
tokenGroup
))
return
}
// check group in common.GroupRatio
// check group in common.GroupRatio
if
_
,
ok
:=
common
.
GroupRatio
[
tokenGroup
];
!
ok
{
if
_
,
ok
:=
common
.
GroupRatio
[
tokenGroup
];
!
ok
{
abortWithOpenAiMessage
(
c
,
http
.
StatusForbidden
,
fmt
.
Sprintf
(
"分组 %s 已被
禁
用"
,
tokenGroup
))
abortWithOpenAiMessage
(
c
,
http
.
StatusForbidden
,
fmt
.
Sprintf
(
"分组 %s 已被
弃
用"
,
tokenGroup
))
return
return
}
}
userGroup
=
tokenGroup
userGroup
=
tokenGroup
...
...
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