wangkaiyue 2 жил өмнө
parent
commit
c5f9e494a7
1 өөрчлөгдсөн 21 нэмэгдсэн , 18 устгасан
  1. 21 18
      internal/model/ws.go

+ 21 - 18
internal/model/ws.go

@@ -82,25 +82,28 @@ func (m *WsChat) Handle(ws *ghttp.WebSocket, msg []byte) {
 			}
 		}
 
-		if from != Answer_ChatGPT {
-			if reply == "" {
-				reply, from = g.Cfg().MustGet(m.Ctx, "limit.emptyMsg").String(), -1
-			}
-			replyId := ChatHistory.Save(m.Ctx, &ChatRecord{
-				Content:    reply,
-				Type:       2,
-				Actions:    gconv.Int(If(errReply == "", 1, 0)),
-				QuestionId: questionId,
-				PersonId:   jSession.PositionId,
-				Item:       gconv.Int(If(errReply == "", from, -1)),
-				CreateTime: time.Now().Format(date.Date_Full_Layout),
-			})
-			if replyId <= 0 {
-				g.Log().Error(m.Ctx, "问答存储存储异常")
-			}
-			return reply, nil, replyId, err
+		if from == Answer_ChatGPT {
+			return reply, buf, 0, nil
+		}
+		if reply == "" {
+			reply, from = g.Cfg().MustGet(m.Ctx, "limit.emptyMsg").String(), -1
+		}
+		replyId := ChatHistory.Save(m.Ctx, &ChatRecord{
+			Content:    reply,
+			Type:       2,
+			Actions:    gconv.Int(If(errReply == "", 1, 0)),
+			QuestionId: questionId,
+			PersonId:   jSession.PositionId,
+			Item:       gconv.Int(If(errReply == "", from, -1)),
+			CreateTime: time.Now().Format(date.Date_Full_Layout),
+		})
+		if replyId <= 0 {
+			g.Log().Error(m.Ctx, "问答存储存储异常")
+		}
+		if errReply != "" {
+			return reply, nil, replyId, fmt.Errorf(errReply)
 		}
-		return reply, buf, 0, err
+		return reply, nil, replyId, nil
 	}()
 	if from != Answer_ChatGPT {
 		if errMsg != nil {