mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	feat: The 'chat_models' field of user table, holds the model IDS in place of the model values
This commit is contained in:
		@@ -131,30 +131,30 @@ const XunFei = Platform("XunFei")
 | 
			
		||||
const QWen = Platform("QWen")
 | 
			
		||||
 | 
			
		||||
type SystemConfig struct {
 | 
			
		||||
	Title         string `json:"title"`
 | 
			
		||||
	AdminTitle    string `json:"admin_title"`
 | 
			
		||||
	Logo          string `json:"logo"`
 | 
			
		||||
	InitPower     int    `json:"init_power"`      // 新用户注册赠送算力值
 | 
			
		||||
	DailyPower    int    `json:"daily_power"`     // 每日赠送算力
 | 
			
		||||
	InvitePower   int    `json:"invite_power"`    // 邀请新用户赠送算力值
 | 
			
		||||
	VipMonthPower int    `json:"vip_month_power"` // VIP 会员每月赠送的算力值
 | 
			
		||||
	Title         string `json:"title,omitempty"`
 | 
			
		||||
	AdminTitle    string `json:"admin_title,omitempty"`
 | 
			
		||||
	Logo          string `json:"logo,omitempty"`
 | 
			
		||||
	InitPower     int    `json:"init_power,omitempty"`      // 新用户注册赠送算力值
 | 
			
		||||
	DailyPower    int    `json:"daily_power,omitempty"`     // 每日赠送算力
 | 
			
		||||
	InvitePower   int    `json:"invite_power,omitempty"`    // 邀请新用户赠送算力值
 | 
			
		||||
	VipMonthPower int    `json:"vip_month_power,omitempty"` // VIP 会员每月赠送的算力值
 | 
			
		||||
 | 
			
		||||
	RegisterWays    []string `json:"register_ways"`    // 注册方式:支持手机,邮箱注册
 | 
			
		||||
	EnabledRegister bool     `json:"enabled_register"` // 是否开放注册
 | 
			
		||||
	RegisterWays    []string `json:"register_ways,omitempty"`    // 注册方式:支持手机,邮箱注册
 | 
			
		||||
	EnabledRegister bool     `json:"enabled_register,omitempty"` // 是否开放注册
 | 
			
		||||
 | 
			
		||||
	RewardImg     string  `json:"reward_img"`     // 众筹收款二维码地址
 | 
			
		||||
	EnabledReward bool    `json:"enabled_reward"` // 启用众筹功能
 | 
			
		||||
	PowerPrice    float64 `json:"power_price"`    // 算力单价
 | 
			
		||||
	RewardImg     string  `json:"reward_img,omitempty"`     // 众筹收款二维码地址
 | 
			
		||||
	EnabledReward bool    `json:"enabled_reward,omitempty"` // 启用众筹功能
 | 
			
		||||
	PowerPrice    float64 `json:"power_price,omitempty"`    // 算力单价
 | 
			
		||||
 | 
			
		||||
	OrderPayTimeout int      `json:"order_pay_timeout"` //订单支付超时时间
 | 
			
		||||
	DefaultModels   []string `json:"default_models"`    // 默认开通的 AI 模型
 | 
			
		||||
	OrderPayTimeout int   `json:"order_pay_timeout,omitempty"` //订单支付超时时间
 | 
			
		||||
	DefaultModels   []int `json:"default_models,omitempty"`    // 默认开通的 AI 模型
 | 
			
		||||
 | 
			
		||||
	MjPower   int `json:"mj_power"`   // MJ 绘画消耗算力
 | 
			
		||||
	SdPower   int `json:"sd_power"`   // SD 绘画消耗算力
 | 
			
		||||
	DallPower int `json:"dall_power"` // DALLE3 绘图消耗算力
 | 
			
		||||
	MjPower   int `json:"mj_power,omitempty"`   // MJ 绘画消耗算力
 | 
			
		||||
	SdPower   int `json:"sd_power,omitempty"`   // SD 绘画消耗算力
 | 
			
		||||
	DallPower int `json:"dall_power,omitempty"` // DALLE3 绘图消耗算力
 | 
			
		||||
 | 
			
		||||
	WechatCardURL string `json:"wechat_card_url"` // 微信客服地址
 | 
			
		||||
	WechatCardURL string `json:"wechat_card_url,omitempty"` // 微信客服地址
 | 
			
		||||
 | 
			
		||||
	EnableContext bool `json:"enable_context"`
 | 
			
		||||
	ContextDeep   int  `json:"context_deep"`
 | 
			
		||||
	EnableContext bool `json:"enable_context,omitempty"`
 | 
			
		||||
	ContextDeep   int  `json:"context_deep,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -26,18 +26,18 @@ func NewChatModelHandler(app *core.AppServer, db *gorm.DB) *ChatModelHandler {
 | 
			
		||||
 | 
			
		||||
func (h *ChatModelHandler) Save(c *gin.Context) {
 | 
			
		||||
	var data struct {
 | 
			
		||||
		Id          uint   `json:"id"`
 | 
			
		||||
		Name        string `json:"name"`
 | 
			
		||||
		Value       string `json:"value"`
 | 
			
		||||
		Enabled     bool   `json:"enabled"`
 | 
			
		||||
		SortNum     int    `json:"sort_num"`
 | 
			
		||||
		Open        bool   `json:"open"`
 | 
			
		||||
		Platform    string `json:"platform"`
 | 
			
		||||
		Power       int    `json:"power"`
 | 
			
		||||
		MaxTokens   int    `json:"max_tokens"`  // 最大响应长度
 | 
			
		||||
		MaxContext  int    `json:"max_context"` // 最大上下文长度
 | 
			
		||||
		Temperature string `json:"temperature"` // 模型温度
 | 
			
		||||
		CreatedAt   int64  `json:"created_at"`
 | 
			
		||||
		Id          uint    `json:"id"`
 | 
			
		||||
		Name        string  `json:"name"`
 | 
			
		||||
		Value       string  `json:"value"`
 | 
			
		||||
		Enabled     bool    `json:"enabled"`
 | 
			
		||||
		SortNum     int     `json:"sort_num"`
 | 
			
		||||
		Open        bool    `json:"open"`
 | 
			
		||||
		Platform    string  `json:"platform"`
 | 
			
		||||
		Power       int     `json:"power"`
 | 
			
		||||
		MaxTokens   int     `json:"max_tokens"`  // 最大响应长度
 | 
			
		||||
		MaxContext  int     `json:"max_context"` // 最大上下文长度
 | 
			
		||||
		Temperature float32 `json:"temperature"` // 模型温度
 | 
			
		||||
		CreatedAt   int64   `json:"created_at"`
 | 
			
		||||
	}
 | 
			
		||||
	if err := c.ShouldBindJSON(&data); err != nil {
 | 
			
		||||
		resp.ERROR(c, types.InvalidArgs)
 | 
			
		||||
@@ -53,7 +53,7 @@ func (h *ChatModelHandler) Save(c *gin.Context) {
 | 
			
		||||
		Open:        data.Open,
 | 
			
		||||
		MaxTokens:   data.MaxTokens,
 | 
			
		||||
		MaxContext:  data.MaxContext,
 | 
			
		||||
		Temperature: float32(utils.Str2Float(data.Temperature)),
 | 
			
		||||
		Temperature: data.Temperature,
 | 
			
		||||
		Power:       data.Power}
 | 
			
		||||
	item.Id = data.Id
 | 
			
		||||
	if item.Id > 0 {
 | 
			
		||||
 
 | 
			
		||||
@@ -25,8 +25,12 @@ func NewConfigHandler(app *core.AppServer, db *gorm.DB) *ConfigHandler {
 | 
			
		||||
 | 
			
		||||
func (h *ConfigHandler) Update(c *gin.Context) {
 | 
			
		||||
	var data struct {
 | 
			
		||||
		Key    string                 `json:"key"`
 | 
			
		||||
		Config map[string]interface{} `json:"config"`
 | 
			
		||||
		Key    string `json:"key"`
 | 
			
		||||
		Config struct {
 | 
			
		||||
			types.SystemConfig
 | 
			
		||||
			Content string `json:"content,omitempty"`
 | 
			
		||||
			Updated bool   `json:"updated,omitempty"`
 | 
			
		||||
		} `json:"config"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := c.ShouldBindJSON(&data); err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -72,7 +72,7 @@ func (h *UserHandler) Save(c *gin.Context) {
 | 
			
		||||
		Password    string   `json:"password"`
 | 
			
		||||
		Username    string   `json:"username"`
 | 
			
		||||
		ChatRoles   []string `json:"chat_roles"`
 | 
			
		||||
		ChatModels  []string `json:"chat_models"`
 | 
			
		||||
		ChatModels  []int    `json:"chat_models"`
 | 
			
		||||
		ExpiredTime string   `json:"expired_time"`
 | 
			
		||||
		Status      bool     `json:"status"`
 | 
			
		||||
		Vip         bool     `json:"vip"`
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,7 @@ func (h *ChatModelHandler) List(c *gin.Context) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var models []string
 | 
			
		||||
	var models []int
 | 
			
		||||
	err = utils.JsonDecode(user.ChatModels, &models)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		resp.ERROR(c, "当前用户没有订阅任何模型")
 | 
			
		||||
@@ -41,7 +41,7 @@ func (h *ChatModelHandler) List(c *gin.Context) {
 | 
			
		||||
 | 
			
		||||
	// 查询用户有权限访问的模型以及所有开放的模型
 | 
			
		||||
	res := h.db.Where("enabled = ?", true).Where(
 | 
			
		||||
		h.db.Where("value IN ?", models).Or("open =?", true),
 | 
			
		||||
		h.db.Where("id IN ?", models).Or("open =?", true),
 | 
			
		||||
	).Order("sort_num ASC").Find(&items)
 | 
			
		||||
	if res.Error == nil {
 | 
			
		||||
		for _, item := range items {
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ type User struct {
 | 
			
		||||
	Salt        string   `json:"salt"`          // 密码盐
 | 
			
		||||
	Power       int      `json:"power"`         // 剩余算力
 | 
			
		||||
	ChatRoles   []string `json:"chat_roles"`    // 聊天角色集合
 | 
			
		||||
	ChatModels  []string `json:"chat_models"`   // AI模型集合
 | 
			
		||||
	ChatModels  []int    `json:"chat_models"`   // AI模型集合
 | 
			
		||||
	ExpiredTime int64    `json:"expired_time"`  // 账户到期时间
 | 
			
		||||
	Status      bool     `json:"status"`        // 当前状态
 | 
			
		||||
	LastLoginAt int64    `json:"last_login_at"` // 最后登录时间
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user