Kaynağa Gözat

✨ feat: Enhance user settings and notification options

CaIon 9 ay önce
ebeveyn
işleme
c418d9ed9a

+ 6 - 5
constant/user_setting.go

@@ -1,11 +1,12 @@
 package constant
 
 var (
-	UserSettingNotifyType            = "notify_type"             // QuotaWarningType 额度预警类型
-	UserSettingQuotaWarningThreshold = "quota_warning_threshold" // QuotaWarningThreshold 额度预警阈值
-	UserSettingWebhookUrl            = "webhook_url"             // WebhookUrl webhook地址
-	UserSettingWebhookSecret         = "webhook_secret"          // WebhookSecret webhook密钥
-	UserSettingNotificationEmail     = "notification_email"      // NotificationEmail 通知邮箱地址
+	UserSettingNotifyType            = "notify_type"                    // QuotaWarningType 额度预警类型
+	UserSettingQuotaWarningThreshold = "quota_warning_threshold"        // QuotaWarningThreshold 额度预警阈值
+	UserSettingWebhookUrl            = "webhook_url"                    // WebhookUrl webhook地址
+	UserSettingWebhookSecret         = "webhook_secret"                 // WebhookSecret webhook密钥
+	UserSettingNotificationEmail     = "notification_email"             // NotificationEmail 通知邮箱地址
+	UserAcceptUnsetRatioModel        = "accept_unset_model_ratio_model" // AcceptUnsetRatioModel 是否接受未设置价格的模型
 )
 
 var (

+ 6 - 4
controller/channel-test.go

@@ -105,6 +105,11 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
 	request := buildTestRequest(testModel)
 	common.SysLog(fmt.Sprintf("testing channel %d with model %s , info %v ", channel.Id, testModel, info))
 
+	priceData, err := helper.ModelPriceHelper(c, info, 0, int(request.MaxTokens))
+	if err != nil {
+		return err, nil
+	}
+
 	adaptor.Init(info)
 
 	convertedRequest, err := adaptor.ConvertOpenAIRequest(c, info, request)
@@ -143,10 +148,7 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
 		return err, nil
 	}
 	info.PromptTokens = usage.PromptTokens
-	priceData, err := helper.ModelPriceHelper(c, info, usage.PromptTokens, int(request.MaxTokens))
-	if err != nil {
-		return err, nil
-	}
+
 	quota := 0
 	if !priceData.UsePrice {
 		quota = usage.PromptTokens + int(math.Round(float64(usage.CompletionTokens)*priceData.CompletionRatio))

+ 7 - 5
controller/user.go

@@ -913,11 +913,12 @@ func TopUp(c *gin.Context) {
 }
 
 type UpdateUserSettingRequest struct {
-	QuotaWarningType      string  `json:"notify_type"`
-	QuotaWarningThreshold float64 `json:"quota_warning_threshold"`
-	WebhookUrl            string  `json:"webhook_url,omitempty"`
-	WebhookSecret         string  `json:"webhook_secret,omitempty"`
-	NotificationEmail     string  `json:"notification_email,omitempty"`
+	QuotaWarningType           string  `json:"notify_type"`
+	QuotaWarningThreshold      float64 `json:"quota_warning_threshold"`
+	WebhookUrl                 string  `json:"webhook_url,omitempty"`
+	WebhookSecret              string  `json:"webhook_secret,omitempty"`
+	NotificationEmail          string  `json:"notification_email,omitempty"`
+	AcceptUnsetModelRatioModel bool    `json:"accept_unset_model_ratio_model"`
 }
 
 func UpdateUserSetting(c *gin.Context) {
@@ -993,6 +994,7 @@ func UpdateUserSetting(c *gin.Context) {
 	settings := map[string]interface{}{
 		constant.UserSettingNotifyType:            req.QuotaWarningType,
 		constant.UserSettingQuotaWarningThreshold: req.QuotaWarningThreshold,
+		"accept_unset_model_ratio_model":          req.AcceptUnsetModelRatioModel,
 	}
 
 	// 如果是webhook类型,添加webhook相关设置

+ 14 - 4
relay/helper/price.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"one-api/common"
+	constant2 "one-api/constant"
 	relaycommon "one-api/relay/common"
 	"one-api/setting"
 	"one-api/setting/operation_setting"
@@ -40,10 +41,19 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens
 		var success bool
 		modelRatio, success = operation_setting.GetModelRatio(info.OriginModelName)
 		if !success {
-			if info.UserId == 1 {
-				return PriceData{}, fmt.Errorf("模型 %s 倍率或价格未配置,请设置或开始自用模式;Model %s ratio or price not set, please set or start self-use mode", info.OriginModelName, info.OriginModelName)
-			} else {
-				return PriceData{}, fmt.Errorf("模型 %s 倍率或价格未配置, 请联系管理员设置;Model %s ratio or price not set, please contact administrator to set", info.OriginModelName, info.OriginModelName)
+			acceptUnsetRatio := false
+			if accept, ok := info.UserSetting[constant2.UserAcceptUnsetRatioModel]; ok {
+				b, ok := accept.(bool)
+				if ok {
+					acceptUnsetRatio = b
+				}
+			}
+			if !acceptUnsetRatio {
+				if info.UserId == 1 {
+					return PriceData{}, fmt.Errorf("模型 %s 倍率或价格未配置,请设置或开始自用模式;Model %s ratio or price not set, please set or start self-use mode", info.OriginModelName, info.OriginModelName)
+				} else {
+					return PriceData{}, fmt.Errorf("模型 %s 倍率或价格未配置, 请联系管理员设置;Model %s ratio or price not set, please contact administrator to set", info.OriginModelName, info.OriginModelName)
+				}
 			}
 		}
 		completionRatio = operation_setting.GetCompletionRatio(info.OriginModelName)

Dosya farkı çok büyük olduğundan ihmal edildi
+ 2141 - 845
web/pnpm-lock.yaml


Dosya farkı çok büyük olduğundan ihmal edildi
+ 804 - 776
web/src/components/PersonalSetting.js


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor