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
191fe6ea
authored
May 15, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 完善模型价格获取逻辑
parent
05b133e6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
14 deletions
+14
-14
controller/model.go
+8
-8
model/pricing.go
+5
-5
router/api-router.go
+1
-1
No files found.
controller/model.go
View file @
191fe6ea
...
@@ -108,8 +108,8 @@ func init() {
...
@@ -108,8 +108,8 @@ func init() {
})
})
}
}
openAIModelsMap
=
make
(
map
[
string
]
dto
.
OpenAIModels
)
openAIModelsMap
=
make
(
map
[
string
]
dto
.
OpenAIModels
)
for
_
,
m
odel
:=
range
openAIModels
{
for
_
,
aiM
odel
:=
range
openAIModels
{
openAIModelsMap
[
model
.
Id
]
=
m
odel
openAIModelsMap
[
aiModel
.
Id
]
=
aiM
odel
}
}
channelId2Models
=
make
(
map
[
int
][]
string
)
channelId2Models
=
make
(
map
[
int
][]
string
)
for
i
:=
1
;
i
<=
common
.
ChannelTypeDummy
;
i
++
{
for
i
:=
1
;
i
<=
common
.
ChannelTypeDummy
;
i
++
{
...
@@ -174,8 +174,8 @@ func DashboardListModels(c *gin.Context) {
...
@@ -174,8 +174,8 @@ func DashboardListModels(c *gin.Context) {
func
RetrieveModel
(
c
*
gin
.
Context
)
{
func
RetrieveModel
(
c
*
gin
.
Context
)
{
modelId
:=
c
.
Param
(
"model"
)
modelId
:=
c
.
Param
(
"model"
)
if
m
odel
,
ok
:=
openAIModelsMap
[
modelId
];
ok
{
if
aiM
odel
,
ok
:=
openAIModelsMap
[
modelId
];
ok
{
c
.
JSON
(
200
,
m
odel
)
c
.
JSON
(
200
,
aiM
odel
)
}
else
{
}
else
{
openAIError
:=
dto
.
OpenAIError
{
openAIError
:=
dto
.
OpenAIError
{
Message
:
fmt
.
Sprintf
(
"The model '%s' does not exist"
,
modelId
),
Message
:
fmt
.
Sprintf
(
"The model '%s' does not exist"
,
modelId
),
...
@@ -191,12 +191,12 @@ func RetrieveModel(c *gin.Context) {
...
@@ -191,12 +191,12 @@ func RetrieveModel(c *gin.Context) {
func
GetPricing
(
c
*
gin
.
Context
)
{
func
GetPricing
(
c
*
gin
.
Context
)
{
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
user
,
_
:=
model
.
GetUserById
(
userId
,
true
)
group
,
err
:=
model
.
CacheGetUserGroup
(
userId
)
groupRatio
:=
common
.
GetGroupRatio
(
"default"
)
groupRatio
:=
common
.
GetGroupRatio
(
"default"
)
if
use
r
!=
nil
{
if
er
r
!=
nil
{
groupRatio
=
common
.
GetGroupRatio
(
user
.
G
roup
)
groupRatio
=
common
.
GetGroupRatio
(
g
roup
)
}
}
pricing
:=
model
.
GetPricing
(
user
,
openAIModels
)
pricing
:=
model
.
GetPricing
(
group
)
c
.
JSON
(
200
,
gin
.
H
{
c
.
JSON
(
200
,
gin
.
H
{
"success"
:
true
,
"success"
:
true
,
"data"
:
pricing
,
"data"
:
pricing
,
...
...
model/pricing.go
View file @
191fe6ea
...
@@ -13,16 +13,16 @@ var (
...
@@ -13,16 +13,16 @@ var (
updatePricingLock
sync
.
Mutex
updatePricingLock
sync
.
Mutex
)
)
func
GetPricing
(
user
*
User
,
openAIModels
[]
dto
.
OpenAIModels
)
[]
dto
.
ModelPricing
{
func
GetPricing
(
group
string
)
[]
dto
.
ModelPricing
{
updatePricingLock
.
Lock
()
updatePricingLock
.
Lock
()
defer
updatePricingLock
.
Unlock
()
defer
updatePricingLock
.
Unlock
()
if
time
.
Since
(
lastGetPricingTime
)
>
time
.
Minute
*
1
||
len
(
pricingMap
)
==
0
{
if
time
.
Since
(
lastGetPricingTime
)
>
time
.
Minute
*
1
||
len
(
pricingMap
)
==
0
{
updatePricing
(
openAIModels
)
updatePricing
()
}
}
if
user
!=
nil
{
if
group
!=
""
{
userPricingMap
:=
make
([]
dto
.
ModelPricing
,
0
)
userPricingMap
:=
make
([]
dto
.
ModelPricing
,
0
)
models
:=
GetGroupModels
(
user
.
G
roup
)
models
:=
GetGroupModels
(
g
roup
)
for
_
,
pricing
:=
range
pricingMap
{
for
_
,
pricing
:=
range
pricingMap
{
if
!
common
.
StringsContains
(
models
,
pricing
.
ModelName
)
{
if
!
common
.
StringsContains
(
models
,
pricing
.
ModelName
)
{
pricing
.
Available
=
false
pricing
.
Available
=
false
...
@@ -34,7 +34,7 @@ func GetPricing(user *User, openAIModels []dto.OpenAIModels) []dto.ModelPricing
...
@@ -34,7 +34,7 @@ func GetPricing(user *User, openAIModels []dto.OpenAIModels) []dto.ModelPricing
return
pricingMap
return
pricingMap
}
}
func
updatePricing
(
openAIModels
[]
dto
.
OpenAIModels
)
{
func
updatePricing
()
{
//modelRatios := common.GetModelRatios()
//modelRatios := common.GetModelRatios()
enabledModels
:=
GetEnabledModels
()
enabledModels
:=
GetEnabledModels
()
allModels
:=
make
(
map
[
string
]
int
)
allModels
:=
make
(
map
[
string
]
int
)
...
...
router/api-router.go
View file @
191fe6ea
...
@@ -20,7 +20,7 @@ func SetApiRouter(router *gin.Engine) {
...
@@ -20,7 +20,7 @@ func SetApiRouter(router *gin.Engine) {
apiRouter
.
GET
(
"/about"
,
controller
.
GetAbout
)
apiRouter
.
GET
(
"/about"
,
controller
.
GetAbout
)
//apiRouter.GET("/midjourney", controller.GetMidjourney)
//apiRouter.GET("/midjourney", controller.GetMidjourney)
apiRouter
.
GET
(
"/home_page_content"
,
controller
.
GetHomePageContent
)
apiRouter
.
GET
(
"/home_page_content"
,
controller
.
GetHomePageContent
)
apiRouter
.
GET
(
"/pricing"
,
middleware
.
CriticalRateLimit
(),
middleware
.
TryUserAuth
(),
controller
.
GetPricing
)
apiRouter
.
GET
(
"/pricing"
,
middleware
.
TryUserAuth
(),
controller
.
GetPricing
)
apiRouter
.
GET
(
"/verification"
,
middleware
.
CriticalRateLimit
(),
middleware
.
TurnstileCheck
(),
controller
.
SendEmailVerification
)
apiRouter
.
GET
(
"/verification"
,
middleware
.
CriticalRateLimit
(),
middleware
.
TurnstileCheck
(),
controller
.
SendEmailVerification
)
apiRouter
.
GET
(
"/reset_password"
,
middleware
.
CriticalRateLimit
(),
middleware
.
TurnstileCheck
(),
controller
.
SendPasswordResetEmail
)
apiRouter
.
GET
(
"/reset_password"
,
middleware
.
CriticalRateLimit
(),
middleware
.
TurnstileCheck
(),
controller
.
SendPasswordResetEmail
)
apiRouter
.
POST
(
"/user/reset"
,
middleware
.
CriticalRateLimit
(),
controller
.
ResetPassword
)
apiRouter
.
POST
(
"/user/reset"
,
middleware
.
CriticalRateLimit
(),
controller
.
ResetPassword
)
...
...
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