Skip to content

Commit

Permalink
merge v4.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjian102621 committed Jun 3, 2024
2 parents 4a99be2 + 114d008 commit 5f820b9
Show file tree
Hide file tree
Showing 53 changed files with 4,845 additions and 1,136 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# 更新日志

## v4.0.6

* Bug修复:修复PC端画廊页面的瀑布流组件样式错乱问题
* 功能新增:给思维导图增加 ToolBar,实现思维导图的放大缩小和定位
* Bug修复:修复思维导图不扣费的Bug
* Bug修复:修复管理后台角色删除失败的Bug
* Bug修复:兼容最新版秋叶SD懒人包的 SD API,新增 scheduler 参数
* 功能优化:支持在管理后台配置 AI 绘图相关配置,包括 SD, MJ-PLUS, MJ-PROXY
* Bug修复:修复注册用户提示注册人数达到上限的 Bug
* 功能优化:将MJ,SD,Dall绘画页面的任务列表全改成瀑布流组件

## v4.0.5

* 功能优化:已授权系统在后台显示授权信息
Expand Down Expand Up @@ -38,6 +49,7 @@
* 功能新增:支持管理后台 Logo 修改

## 4.0.2

* 功能新增:支持前端菜单可以配置
* 功能优化:在登录和注册界面标题显示软件版本号
* 功能优化:MJ 绘画支持 --sref 和 --cref 图片一致性参数
Expand Down
2 changes: 2 additions & 0 deletions api/core/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,6 @@ type SystemConfig struct {

EnableContext bool `json:"enable_context,omitempty"`
ContextDeep int `json:"context_deep,omitempty"`

SdNegPrompt string `json:"sd_neg_prompt"` // SD 默认反向提示词
}
7 changes: 4 additions & 3 deletions api/core/types/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ type SdTaskParams struct {
NegPrompt string `json:"neg_prompt"` // 反向提示词
Steps int `json:"steps"` // 迭代步数,默认20
Sampler string `json:"sampler"` // 采样器
FaceFix bool `json:"face_fix"` // 面部修复
CfgScale float32 `json:"cfg_scale"` //引导系数,默认 7
Seed int64 `json:"seed"` // 随机数种子
Scheduler string `json:"scheduler"`
FaceFix bool `json:"face_fix"` // 面部修复
CfgScale float32 `json:"cfg_scale"` //引导系数,默认 7
Seed int64 `json:"seed"` // 随机数种子
Height int `json:"height"`
Width int `json:"width"`
HdFix bool `json:"hd_fix"` // 启用高清修复
Expand Down
1 change: 1 addition & 0 deletions api/handler/admin/chat_model_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"geekai/store/vo"
"geekai/utils"
"geekai/utils/resp"

"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
Expand Down
13 changes: 4 additions & 9 deletions api/handler/admin/chat_role_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,13 @@ func (h *ChatRoleHandler) Set(c *gin.Context) {
}

func (h *ChatRoleHandler) Remove(c *gin.Context) {
var data struct {
Id uint
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
return
}
if data.Id <= 0 {
id := h.GetInt(c, "id", 0)

if id <= 0 {
resp.ERROR(c, types.InvalidArgs)
return
}
res := h.DB.Where("id = ?", data.Id).Delete(&model.ChatRole{})
res := h.DB.Where("id", id).Delete(&model.ChatRole{})
if res.Error != nil {
resp.ERROR(c, "删除失败!")
return
Expand Down
5 changes: 3 additions & 2 deletions api/handler/chat_model_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"geekai/store/vo"
"geekai/utils"
"geekai/utils/resp"

"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
Expand All @@ -32,7 +33,7 @@ func (h *ChatModelHandler) List(c *gin.Context) {
var res *gorm.DB
// 如果用户没有登录,则加载所有开放模型
if !h.IsLogin(c) {
res = h.DB.Where("enabled = ?", true).Where("open =?", true).Order("sort_num ASC").Find(&items)
res = h.DB.Where("enabled", true).Where("open", true).Order("sort_num ASC").Find(&items)
} else {
user, _ := h.GetLoginUser(c)
var models []int
Expand All @@ -43,7 +44,7 @@ func (h *ChatModelHandler) List(c *gin.Context) {
}
// 查询用户有权限访问的模型以及所有开放的模型
res = h.DB.Where("enabled = ?", true).Where(
h.DB.Where("id IN ?", models).Or("open =?", true),
h.DB.Where("id IN ?", models).Or("open", true),
).Order("sort_num ASC").Find(&items)
}

Expand Down
22 changes: 7 additions & 15 deletions api/handler/chatimpl/azure_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ package chatimpl

import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"geekai/core/types"
"geekai/store/model"
"geekai/store/vo"
"geekai/utils"
"context"
"encoding/json"
"fmt"
"html/template"
"io"
"strings"
Expand Down Expand Up @@ -44,14 +45,9 @@ func (h *ChatHandler) sendAzureMessage(
logger.Info("用户取消了请求:", prompt)
return nil
} else if strings.Contains(err.Error(), "no available key") {
utils.ReplyMessage(ws, "抱歉😔😔😔,系统已经没有可用的 API KEY,请联系管理员!")
return nil
} else {
logger.Error(err)
return errors.New("抱歉😔😔😔,系统已经没有可用的 API KEY,请联系管理员!")
}

utils.ReplyMessage(ws, ErrorMsg)
utils.ReplyMessage(ws, ErrImg)
return err
} else {
defer response.Body.Close()
Expand All @@ -73,10 +69,7 @@ func (h *ChatHandler) sendAzureMessage(
var responseBody = types.ApiResponse{}
err = json.Unmarshal([]byte(line[6:]), &responseBody)
if err != nil { // 数据解析出错
logger.Error(err, line)
utils.ReplyMessage(ws, ErrorMsg)
utils.ReplyMessage(ws, ErrImg)
break
return errors.New(line)
}

if len(responseBody.Choices) == 0 {
Expand Down Expand Up @@ -203,11 +196,10 @@ func (h *ChatHandler) sendAzureMessage(

if strings.Contains(res.Error.Message, "maximum context length") {
logger.Error(res.Error.Message)
utils.ReplyMessage(ws, "当前会话上下文长度超出限制,已为您清空会话上下文!")
h.App.ChatContexts.Delete(session.ChatId)
return h.sendMessage(ctx, session, role, prompt, ws)
} else {
utils.ReplyMessage(ws, "请求 Azure API 失败:"+res.Error.Message)
return fmt.Errorf("请求 Azure API 失败:%v", res.Error)
}
}

Expand Down
15 changes: 5 additions & 10 deletions api/handler/chatimpl/baidu_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ package chatimpl

import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"geekai/core/types"
"geekai/store/model"
"geekai/store/vo"
"geekai/utils"
"context"
"encoding/json"
"fmt"
"html/template"
"io"
"net/http"
Expand Down Expand Up @@ -61,14 +62,8 @@ func (h *ChatHandler) sendBaiduMessage(
logger.Info("用户取消了请求:", prompt)
return nil
} else if strings.Contains(err.Error(), "no available key") {
utils.ReplyMessage(ws, "抱歉😔😔😔,系统已经没有可用的 API KEY,请联系管理员!")
return nil
} else {
logger.Error(err)
return errors.New("抱歉😔😔😔,系统已经没有可用的 API KEY,请联系管理员!")
}

utils.ReplyMessage(ws, ErrorMsg)
utils.ReplyMessage(ws, ErrImg)
return err
} else {
defer response.Body.Close()
Expand Down
30 changes: 9 additions & 21 deletions api/handler/chatimpl/chat_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
err = h.sendMessage(ctx, session, chatRole, utils.InterfaceToString(message.Content), client)
if err != nil {
logger.Error(err)
utils.ReplyChunkMessage(client, types.WsMessage{Type: types.WsEnd})
utils.ReplyMessage(client, err.Error())
} else {
utils.ReplyChunkMessage(client, types.WsMessage{Type: types.WsEnd})
logger.Infof("回答完毕: %v", message.Content)
Expand All @@ -195,8 +195,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
var user model.User
res := h.DB.Model(&model.User{}).First(&user, session.UserId)
if res.Error != nil {
utils.ReplyMessage(ws, "未授权用户,您正在进行非法操作!")
return res.Error
return errors.New("未授权用户,您正在进行非法操作!")
}
var userVo vo.User
err := utils.CopyObject(user, &userVo)
Expand All @@ -206,28 +205,22 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
}

if userVo.Status == false {
utils.ReplyMessage(ws, "您的账号已经被禁用,如果疑问,请联系管理员!")
utils.ReplyMessage(ws, ErrImg)
return nil
return errors.New("您的账号已经被禁用,如果疑问,请联系管理员!")
}

if userVo.Power < session.Model.Power {
utils.ReplyMessage(ws, fmt.Sprintf("您当前剩余算力(%d)已不足以支付当前模型的单次对话需要消耗的算力(%d)!", userVo.Power, session.Model.Power))
utils.ReplyMessage(ws, ErrImg)
return nil
return fmt.Errorf("您当前剩余算力(%d)已不足以支付当前模型的单次对话需要消耗的算力(%d)!", userVo.Power, session.Model.Power)
}

if userVo.ExpiredTime > 0 && userVo.ExpiredTime <= time.Now().Unix() {
utils.ReplyMessage(ws, "您的账号已经过期,请联系管理员!")
utils.ReplyMessage(ws, ErrImg)
return nil
return errors.New("您的账号已经过期,请联系管理员!")
}

// 检查 prompt 长度是否超过了当前模型允许的最大上下文长度
promptTokens, err := utils.CalcTokens(prompt, session.Model.Value)
if promptTokens > session.Model.MaxContext {
utils.ReplyMessage(ws, "对话内容超出了当前模型允许的最大上下文长度!")
return nil

return errors.New("对话内容超出了当前模型允许的最大上下文长度!")
}

var req = types.ApiRequest{
Expand Down Expand Up @@ -286,9 +279,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
break

default:
utils.ReplyMessage(ws, "不支持的平台:"+session.Model.Platform+",请联系管理员!")
utils.ReplyMessage(ws, ErrImg)
return nil
return fmt.Errorf("不支持的平台:%s", session.Model.Platform)
}

// 加载聊天上下文
Expand Down Expand Up @@ -402,10 +393,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
case types.QWen:
return h.sendQWenMessage(chatCtx, req, userVo, ctx, session, role, prompt, ws)
}
utils.ReplyChunkMessage(ws, types.WsMessage{
Type: types.WsMiddle,
Content: fmt.Sprintf("Not supported platform: %s", session.Model.Platform),
})

return nil
}

Expand Down
15 changes: 5 additions & 10 deletions api/handler/chatimpl/chatglm_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ package chatimpl

import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"geekai/core/types"
"geekai/store/model"
"geekai/store/vo"
"geekai/utils"
"context"
"encoding/json"
"fmt"
"github.com/golang-jwt/jwt/v5"
"html/template"
"io"
Expand Down Expand Up @@ -45,14 +46,8 @@ func (h *ChatHandler) sendChatGLMMessage(
logger.Info("用户取消了请求:", prompt)
return nil
} else if strings.Contains(err.Error(), "no available key") {
utils.ReplyMessage(ws, "抱歉😔😔😔,系统已经没有可用的 API KEY,请联系管理员!")
return nil
} else {
logger.Error(err)
return errors.New("抱歉😔😔😔,系统已经没有可用的 API KEY,请联系管理员!")
}

utils.ReplyMessage(ws, ErrorMsg)
utils.ReplyMessage(ws, ErrImg)
return err
} else {
defer response.Body.Close()
Expand Down
6 changes: 2 additions & 4 deletions api/handler/chatimpl/openai_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"geekai/core/types"
"geekai/store/model"
Expand Down Expand Up @@ -76,10 +77,7 @@ func (h *ChatHandler) sendOpenAiMessage(
var responseBody = types.ApiResponse{}
err = json.Unmarshal([]byte(line[6:]), &responseBody)
if err != nil { // 数据解析出错
logger.Error(err, line)
utils.ReplyMessage(ws, ErrorMsg)
utils.ReplyMessage(ws, ErrImg)
break
return errors.New(line)
}
if len(responseBody.Choices) == 0 { // Fixed: 兼容 Azure API 第一个输出空行
continue
Expand Down
15 changes: 5 additions & 10 deletions api/handler/chatimpl/qwen_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ package chatimpl

import (
"bufio"
"context"
"encoding/json"
"fmt"
"geekai/core/types"
"geekai/store/model"
"geekai/store/vo"
"geekai/utils"
"context"
"encoding/json"
"fmt"
"github.com/syndtr/goleveldb/leveldb/errors"
"html/template"
"io"
"strings"
Expand Down Expand Up @@ -59,14 +60,8 @@ func (h *ChatHandler) sendQWenMessage(
logger.Info("用户取消了请求:", prompt)
return nil
} else if strings.Contains(err.Error(), "no available key") {
utils.ReplyMessage(ws, "抱歉😔😔😔,系统已经没有可用的 API KEY,请联系管理员!")
return nil
} else {
logger.Error(err)
return errors.New("抱歉😔😔😔,系统已经没有可用的 API KEY,请联系管理员!")
}

utils.ReplyMessage(ws, ErrorMsg)
utils.ReplyMessage(ws, ErrImg)
return err
} else {
defer response.Body.Close()
Expand Down
2 changes: 1 addition & 1 deletion api/handler/chatimpl/xunfei_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (h *ChatHandler) sendXunFeiMessage(
res = h.DB.Where("id", session.Model.KeyId).Where("enabled", true).Find(&apiKey)
}
// use the last unused key
if res.Error != nil {
if apiKey.Id == 0 {
res = h.DB.Where("platform", session.Model.Platform).Where("type", "chat").Where("enabled", true).Order("last_used_at ASC").First(&apiKey)
}
if res.Error != nil {
Expand Down
3 changes: 1 addition & 2 deletions api/handler/dalle_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ func (h *DallJobHandler) preCheck(c *gin.Context) bool {
resp.NotAuth(c)
return false
}

if user.Power < h.App.SysConfig.SdPower {
if user.Power < h.App.SysConfig.DallPower {
resp.ERROR(c, "当前用户剩余算力不足以完成本次绘画!")
return false
}
Expand Down
Loading

0 comments on commit 5f820b9

Please sign in to comment.