refactor: add system config key 'user_init_calls' to init the new register user's api calls

This commit is contained in:
RockYang
2023-06-15 10:06:21 +08:00
parent 567cdc6f8d
commit 197714a57a
5 changed files with 23 additions and 9 deletions

View File

@@ -167,7 +167,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
if res.Error == nil {
for _, msg := range historyMessages {
ms := types.Message{Role: "user", Content: msg.Content}
if msg.Type == types.REPLY_MSG {
if msg.Type == types.ReplyMsg {
ms.Role = "assistant"
}
chatCtx = append(chatCtx, ms)
@@ -276,7 +276,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
UserId: userVo.Id,
ChatId: session.ChatId,
RoleId: role.Id,
Type: types.PROMPT_MSG,
Type: types.PromptMsg,
Icon: user.Avatar,
Content: prompt,
Tokens: token,
@@ -297,7 +297,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
UserId: userVo.Id,
ChatId: session.ChatId,
RoleId: role.Id,
Type: types.REPLY_MSG,
Type: types.ReplyMsg,
Icon: role.Icon,
Content: message.Content,
Tokens: token,

View File

@@ -52,6 +52,7 @@ func (h *ConfigHandler) Update(c *gin.Context) {
resp.SUCCESS(c, config)
}
// Get 获取指定的系统配置
func (h *ConfigHandler) Get(c *gin.Context) {
key := c.Query("key")
var config model.Config

View File

@@ -85,6 +85,16 @@ func (h *UserHandler) Register(c *gin.Context) {
ApiKey: "",
}),
}
// 初始化调用次数
var cfg model.Config
h.db.Where("marker = ?", "system").First(&cfg)
var config types.SystemConfig
err := utils.JsonDecode(cfg.Config, &config)
if err != nil || config.UserInitCalls <= 0 {
user.Calls = types.UserInitCalls
} else {
user.Calls = config.UserInitCalls
}
res := h.db.Create(&user)
if res.Error != nil {
resp.ERROR(c, "保存数据失败")