feat: 支持讯飞大模型 v3.0

This commit is contained in:
RockYang
2023-11-23 07:11:13 +08:00
parent 13fbbc190a
commit 191e3b7d2c
8 changed files with 41 additions and 18 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)