mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	feat: 支持讯飞大模型 v3.0
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
		}),
 | 
			
		||||
 
 | 
			
		||||
@@ -7,5 +7,6 @@ type ChatModel struct {
 | 
			
		||||
	Value    string // API Key 的值
 | 
			
		||||
	SortNum  int
 | 
			
		||||
	Enabled  bool
 | 
			
		||||
	Weight   int // 对话权重,每次对话扣减多少次对话额度
 | 
			
		||||
	Weight   int  // 对话权重,每次对话扣减多少次对话额度
 | 
			
		||||
	Open     bool // 是否开放模型给所有人使用
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,4 +8,5 @@ type ChatModel struct {
 | 
			
		||||
	Enabled  bool   `json:"enabled"`
 | 
			
		||||
	SortNum  int    `json:"sort_num"`
 | 
			
		||||
	Weight   int    `json:"weight"`
 | 
			
		||||
	Open     bool   `json:"open"`
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								database/update-v3.1.9.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								database/update-v3.1.9.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
ALTER TABLE `chatgpt_chat_models` ADD `open` TINYINT(1) NOT NULL COMMENT '是否开放模型' AFTER `weight`;
 | 
			
		||||
@@ -17,7 +17,12 @@
 | 
			
		||||
        <el-table-column prop="weight" label="对话权重"/>
 | 
			
		||||
        <el-table-column prop="enabled" label="启用状态">
 | 
			
		||||
          <template #default="scope">
 | 
			
		||||
            <el-switch v-model="scope.row['enabled']" @change="enable(scope.row)"/>
 | 
			
		||||
            <el-switch v-model="scope.row['enabled']" @change="modelSet('enabled',scope.row)"/>
 | 
			
		||||
          </template>
 | 
			
		||||
        </el-table-column>
 | 
			
		||||
        <el-table-column prop="enabled" label="开放状态">
 | 
			
		||||
          <template #default="scope">
 | 
			
		||||
            <el-switch v-model="scope.row['open']" @change="modelSet('open',scope.row)"/>
 | 
			
		||||
          </template>
 | 
			
		||||
        </el-table-column>
 | 
			
		||||
 | 
			
		||||
@@ -84,6 +89,9 @@
 | 
			
		||||
        <el-form-item label="启用状态:" prop="enable">
 | 
			
		||||
          <el-switch v-model="item.enabled"/>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
        <el-form-item label="开放状态:" prop="open">
 | 
			
		||||
          <el-switch v-model="item.open"/>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
      </el-form>
 | 
			
		||||
 | 
			
		||||
      <template #footer>
 | 
			
		||||
@@ -200,8 +208,8 @@ const save = function () {
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const enable = (row) => {
 | 
			
		||||
  httpPost('/api/admin/model/enable', {id: row.id, enabled: row.enabled}).then(() => {
 | 
			
		||||
const modelSet = (filed, row) => {
 | 
			
		||||
  httpPost('/api/admin/model/set', {id: row.id, filed: filed, value: row[filed]}).then(() => {
 | 
			
		||||
    ElMessage.success("操作成功!")
 | 
			
		||||
  }).catch(e => {
 | 
			
		||||
    ElMessage.error("操作失败:" + e.message)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user