@@ -16,6 +16,8 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/relay/channel/moonshot"
|
"github.com/QuantumNous/new-api/relay/channel/moonshot"
|
||||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||||
"github.com/QuantumNous/new-api/service"
|
"github.com/QuantumNous/new-api/service"
|
||||||
|
"github.com/QuantumNous/new-api/setting/operation_setting"
|
||||||
|
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
@@ -109,6 +111,17 @@ func init() {
|
|||||||
func ListModels(c *gin.Context, modelType int) {
|
func ListModels(c *gin.Context, modelType int) {
|
||||||
userOpenAiModels := make([]dto.OpenAIModels, 0)
|
userOpenAiModels := make([]dto.OpenAIModels, 0)
|
||||||
|
|
||||||
|
acceptUnsetRatioModel := operation_setting.SelfUseModeEnabled
|
||||||
|
if !acceptUnsetRatioModel {
|
||||||
|
userId := c.GetInt("id")
|
||||||
|
if userId > 0 {
|
||||||
|
userSettings, _ := model.GetUserSetting(userId, false)
|
||||||
|
if userSettings.AcceptUnsetRatioModel {
|
||||||
|
acceptUnsetRatioModel = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
modelLimitEnable := common.GetContextKeyBool(c, constant.ContextKeyTokenModelLimitEnabled)
|
modelLimitEnable := common.GetContextKeyBool(c, constant.ContextKeyTokenModelLimitEnabled)
|
||||||
if modelLimitEnable {
|
if modelLimitEnable {
|
||||||
s, ok := common.GetContextKey(c, constant.ContextKeyTokenModelLimit)
|
s, ok := common.GetContextKey(c, constant.ContextKeyTokenModelLimit)
|
||||||
@@ -119,6 +132,12 @@ func ListModels(c *gin.Context, modelType int) {
|
|||||||
tokenModelLimit = map[string]bool{}
|
tokenModelLimit = map[string]bool{}
|
||||||
}
|
}
|
||||||
for allowModel, _ := range tokenModelLimit {
|
for allowModel, _ := range tokenModelLimit {
|
||||||
|
if !acceptUnsetRatioModel {
|
||||||
|
_, _, exist := ratio_setting.GetModelRatioOrPrice(allowModel)
|
||||||
|
if !exist {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
if oaiModel, ok := openAIModelsMap[allowModel]; ok {
|
if oaiModel, ok := openAIModelsMap[allowModel]; ok {
|
||||||
oaiModel.SupportedEndpointTypes = model.GetModelSupportEndpointTypes(allowModel)
|
oaiModel.SupportedEndpointTypes = model.GetModelSupportEndpointTypes(allowModel)
|
||||||
userOpenAiModels = append(userOpenAiModels, oaiModel)
|
userOpenAiModels = append(userOpenAiModels, oaiModel)
|
||||||
@@ -161,6 +180,12 @@ func ListModels(c *gin.Context, modelType int) {
|
|||||||
models = model.GetGroupEnabledModels(group)
|
models = model.GetGroupEnabledModels(group)
|
||||||
}
|
}
|
||||||
for _, modelName := range models {
|
for _, modelName := range models {
|
||||||
|
if !acceptUnsetRatioModel {
|
||||||
|
_, _, exist := ratio_setting.GetModelRatioOrPrice(modelName)
|
||||||
|
if !exist {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
if oaiModel, ok := openAIModelsMap[modelName]; ok {
|
if oaiModel, ok := openAIModelsMap[modelName]; ok {
|
||||||
oaiModel.SupportedEndpointTypes = model.GetModelSupportEndpointTypes(modelName)
|
oaiModel.SupportedEndpointTypes = model.GetModelSupportEndpointTypes(modelName)
|
||||||
userOpenAiModels = append(userOpenAiModels, oaiModel)
|
userOpenAiModels = append(userOpenAiModels, oaiModel)
|
||||||
@@ -175,6 +200,7 @@ func ListModels(c *gin.Context, modelType int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch modelType {
|
switch modelType {
|
||||||
case constant.ChannelTypeAnthropic:
|
case constant.ChannelTypeAnthropic:
|
||||||
useranthropicModels := make([]dto.AnthropicModel, len(userOpenAiModels))
|
useranthropicModels := make([]dto.AnthropicModel, len(userOpenAiModels))
|
||||||
|
|||||||
@@ -823,3 +823,16 @@ func FormatMatchingModelName(name string) string {
|
|||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// result: 倍率or价格, usePrice, exist
|
||||||
|
func GetModelRatioOrPrice(model string) (float64, bool, bool) { // price or ratio
|
||||||
|
price, usePrice := GetModelPrice(model, false)
|
||||||
|
if usePrice {
|
||||||
|
return price, true, true
|
||||||
|
}
|
||||||
|
modelRatio, success, _ := GetModelRatio(model)
|
||||||
|
if success {
|
||||||
|
return modelRatio, false, true
|
||||||
|
}
|
||||||
|
return 37.5, false, false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user