diff --git a/api/handler/admin/chat_model_handler.go b/api/handler/admin/chat_model_handler.go index 1232175c..5aa83f0f 100644 --- a/api/handler/admin/chat_model_handler.go +++ b/api/handler/admin/chat_model_handler.go @@ -31,6 +31,7 @@ func (h *ChatModelHandler) Save(c *gin.Context) { Value string `json:"value"` Enabled bool `json:"enabled"` SortNum int `json:"sort_num"` + Open bool `json:"open"` Platform string `json:"platform"` Weight int `json:"weight"` CreatedAt int64 `json:"created_at"` @@ -40,7 +41,14 @@ func (h *ChatModelHandler) Save(c *gin.Context) { return } - item := model.ChatModel{Platform: data.Platform, Name: data.Name, Value: data.Value, Enabled: data.Enabled, SortNum: data.SortNum, Weight: data.Weight} + item := model.ChatModel{ + Platform: data.Platform, + Name: data.Name, + Value: data.Value, + Enabled: data.Enabled, + SortNum: data.SortNum, + Open: data.Open, + Weight: data.Weight} item.Id = data.Id if item.Id > 0 { item.CreatedAt = time.Unix(data.CreatedAt, 0) @@ -89,10 +97,11 @@ func (h *ChatModelHandler) List(c *gin.Context) { resp.SUCCESS(c, cms) } -func (h *ChatModelHandler) Enable(c *gin.Context) { +func (h *ChatModelHandler) Set(c *gin.Context) { var data struct { - Id uint `json:"id"` - Enabled bool `json:"enabled"` + Id uint `json:"id"` + Filed string `json:"filed"` + Value interface{} `json:"value"` } if err := c.ShouldBindJSON(&data); err != nil { @@ -100,7 +109,7 @@ func (h *ChatModelHandler) Enable(c *gin.Context) { return } - res := h.db.Model(&model.ChatModel{}).Where("id = ?", data.Id).Update("enabled", data.Enabled) + res := h.db.Model(&model.ChatModel{}).Where("id = ?", data.Id).Update(data.Filed, data.Value) if res.Error != nil { resp.ERROR(c, "更新数据库失败!") return diff --git a/api/handler/chat_model_handler.go b/api/handler/chat_model_handler.go index 949a45a2..cc8cfa61 100644 --- a/api/handler/chat_model_handler.go +++ b/api/handler/chat_model_handler.go @@ -39,7 +39,10 @@ func (h *ChatModelHandler) List(c *gin.Context) { return } - res := h.db.Where("enabled = ?", true).Where("value IN ?", models).Order("sort_num ASC").Find(&items) + // 查询用户有权限访问的模型以及所有开放的模型 + res := h.db.Where("enabled = ?", true).Where( + h.db.Where("value IN ?", models).Or("open =?", true), + ).Order("sort_num ASC").Find(&items) if res.Error == nil { for _, item := range items { var cm vo.ChatModel diff --git a/api/handler/chatimpl/xunfei_handler.go b/api/handler/chatimpl/xunfei_handler.go index 02d0c485..8bbc3084 100644 --- a/api/handler/chatimpl/xunfei_handler.go +++ b/api/handler/chatimpl/xunfei_handler.go @@ -48,6 +48,12 @@ type xunFeiResp struct { } `json:"payload"` } +var Model2URL = map[string]string{ + "generalv1": "1.1", + "generalv2": "v2.1", + "generalv3": "v3.1", +} + // 科大讯飞消息发送实现 func (h *ChatHandler) sendXunFeiMessage( @@ -82,13 +88,7 @@ func (h *ChatHandler) sendXunFeiMessage( return nil } - var apiURL string - if req.Model == "generalv2" { - apiURL = strings.Replace(h.App.ChatConfig.XunFei.ApiURL, "{version}", "v2.1", 1) - } else { - apiURL = strings.Replace(h.App.ChatConfig.XunFei.ApiURL, "{version}", "v1.1", 1) - } - + apiURL := strings.Replace(h.App.ChatConfig.XunFei.ApiURL, "{version}", Model2URL[req.Model], 1) wsURL, err := assembleAuthUrl(apiURL, key[1], key[2]) //握手并建立websocket 连接 conn, resp, err := d.Dial(wsURL, nil) diff --git a/api/main.go b/api/main.go index 0c9923f5..e77d58e8 100644 --- a/api/main.go +++ b/api/main.go @@ -313,7 +313,7 @@ func main() { group := s.Engine.Group("/api/admin/model/") group.POST("save", h.Save) group.GET("list", h.List) - group.POST("enable", h.Enable) + group.POST("set", h.Set) group.POST("sort", h.Sort) group.GET("remove", h.Remove) }), diff --git a/api/store/model/chat_model.go b/api/store/model/chat_model.go index fb8a63ec..b223d34a 100644 --- a/api/store/model/chat_model.go +++ b/api/store/model/chat_model.go @@ -7,5 +7,6 @@ type ChatModel struct { Value string // API Key 的值 SortNum int Enabled bool - Weight int // 对话权重,每次对话扣减多少次对话额度 + Weight int // 对话权重,每次对话扣减多少次对话额度 + Open bool // 是否开放模型给所有人使用 } diff --git a/api/store/vo/chat_model.go b/api/store/vo/chat_model.go index 7ed783ec..72e164fa 100644 --- a/api/store/vo/chat_model.go +++ b/api/store/vo/chat_model.go @@ -8,4 +8,5 @@ type ChatModel struct { Enabled bool `json:"enabled"` SortNum int `json:"sort_num"` Weight int `json:"weight"` + Open bool `json:"open"` } diff --git a/database/update-v3.1.9.sql b/database/update-v3.1.9.sql new file mode 100644 index 00000000..d2f76fbe --- /dev/null +++ b/database/update-v3.1.9.sql @@ -0,0 +1 @@ +ALTER TABLE `chatgpt_chat_models` ADD `open` TINYINT(1) NOT NULL COMMENT '是否开放模型' AFTER `weight`; \ No newline at end of file diff --git a/web/src/views/admin/ChatModel.vue b/web/src/views/admin/ChatModel.vue index 308a06cd..c6c90eac 100644 --- a/web/src/views/admin/ChatModel.vue +++ b/web/src/views/admin/ChatModel.vue @@ -17,7 +17,12 @@ + + + @@ -84,6 +89,9 @@ + + +