mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-07 01:33:43 +08:00
opt:Optimize the algorithm to check whether Midjourney images can continue to variation
This commit is contained in:
@@ -49,9 +49,6 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
// 设置读写超时时间
|
||||
//_ = ws.SetWriteDeadline(time.Now().Add(300 * time.Second))
|
||||
//_ = ws.SetReadDeadline(time.Now().Add(300 * time.Second))
|
||||
|
||||
sessionId := c.Query("session_id")
|
||||
roleId := h.GetInt(c, "role_id", 0)
|
||||
@@ -59,14 +56,14 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
|
||||
chatModel := c.Query("model")
|
||||
|
||||
session := h.App.ChatSession.Get(sessionId)
|
||||
if session.SessionId == "" {
|
||||
if session == nil {
|
||||
user, err := utils.GetLoginUser(c, h.db)
|
||||
if err != nil {
|
||||
logger.Info("用户未登录")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
session = types.ChatSession{
|
||||
session = &types.ChatSession{
|
||||
SessionId: sessionId,
|
||||
ClientIP: c.ClientIP(),
|
||||
Username: user.Username,
|
||||
@@ -137,7 +134,7 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 将消息发送给 ChatGPT 并获取结果,通过 WebSocket 推送到客户端
|
||||
func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession, role model.ChatRole, prompt string, ws *types.WsClient) error {
|
||||
func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSession, role model.ChatRole, prompt string, ws *types.WsClient) error {
|
||||
promptCreatedAt := time.Now() // 记录提问时间
|
||||
|
||||
var user model.User
|
||||
|
||||
@@ -67,7 +67,7 @@ func (h *MidJourneyHandler) Notify(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Infof("收到 MidJourney 回调请求:%+v", data)
|
||||
logger.Debugf("收到 MidJourney 回调请求:%+v", data)
|
||||
|
||||
// the job is saved
|
||||
var job model.MidJourneyJob
|
||||
|
||||
@@ -157,7 +157,6 @@ func (h *UserHandler) Login(c *gin.Context) {
|
||||
user.LastLoginAt = time.Now().Unix()
|
||||
h.db.Model(&user).Updates(user)
|
||||
|
||||
sessionId := utils.RandString(42)
|
||||
err := utils.SetLoginUser(c, user)
|
||||
if err != nil {
|
||||
resp.ERROR(c, "保存会话失败")
|
||||
@@ -165,9 +164,6 @@ func (h *UserHandler) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 记录登录信息在服务端
|
||||
h.App.ChatSession.Put(sessionId, types.ChatSession{ClientIP: c.ClientIP(), UserId: user.Id, Username: data.Username, SessionId: sessionId})
|
||||
|
||||
h.db.Create(&model.UserLoginLog{
|
||||
UserId: user.Id,
|
||||
Username: user.Username,
|
||||
@@ -175,7 +171,7 @@ func (h *UserHandler) Login(c *gin.Context) {
|
||||
LoginAddress: utils.Ip2Region(h.searcher, c.ClientIP()),
|
||||
})
|
||||
|
||||
resp.SUCCESS(c, sessionId)
|
||||
resp.SUCCESS(c)
|
||||
}
|
||||
|
||||
// Logout 注 销
|
||||
|
||||
Reference in New Issue
Block a user