|
@@ -81,12 +81,12 @@ func (m *WsChat) Handle(ws *ghttp.WebSocket, msg []byte) {
|
|
reply, from = g.Cfg().MustGet(m.Ctx, "limit.errMsg").String(), -1
|
|
reply, from = g.Cfg().MustGet(m.Ctx, "limit.errMsg").String(), -1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
if from == Answer_ChatGPT {
|
|
if from == Answer_ChatGPT {
|
|
return reply, res, 0, nil
|
|
return reply, res, 0, nil
|
|
}
|
|
}
|
|
if reply == "" {
|
|
if reply == "" {
|
|
reply = g.Cfg().MustGet(m.Ctx, "limit.emptyMsg").String()
|
|
reply = g.Cfg().MustGet(m.Ctx, "limit.emptyMsg").String()
|
|
|
|
+ errReply = g.Cfg().MustGet(m.Ctx, "limit.emptyMsg").String()
|
|
}
|
|
}
|
|
replyId := ChatHistory.Save(m.Ctx, &ChatRecord{
|
|
replyId := ChatHistory.Save(m.Ctx, &ChatRecord{
|
|
Content: reply,
|
|
Content: reply,
|
|
@@ -94,7 +94,7 @@ func (m *WsChat) Handle(ws *ghttp.WebSocket, msg []byte) {
|
|
Actions: gconv.Int(If(errReply == "", 1, 0)),
|
|
Actions: gconv.Int(If(errReply == "", 1, 0)),
|
|
QuestionId: questionId,
|
|
QuestionId: questionId,
|
|
PersonId: jSession.PositionId,
|
|
PersonId: jSession.PositionId,
|
|
- Item: gconv.Int(If(errReply == "", from, -1)),
|
|
|
|
|
|
+ Item: from,
|
|
CreateTime: time.Now().Format(date.Date_Full_Layout),
|
|
CreateTime: time.Now().Format(date.Date_Full_Layout),
|
|
})
|
|
})
|
|
if replyId <= 0 {
|
|
if replyId <= 0 {
|
|
@@ -116,25 +116,31 @@ func (m *WsChat) Handle(ws *ghttp.WebSocket, msg []byte) {
|
|
}
|
|
}
|
|
} else if res != nil {
|
|
} else if res != nil {
|
|
buf, lastData := bufio.NewReader(res), &BufRes{}
|
|
buf, lastData := bufio.NewReader(res), &BufRes{}
|
|
|
|
+ isEmpty := true
|
|
for {
|
|
for {
|
|
line, _, err := buf.ReadLine()
|
|
line, _, err := buf.ReadLine()
|
|
if err == io.EOF {
|
|
if err == io.EOF {
|
|
//放回链接池
|
|
//放回链接池
|
|
ChatGptPool.Add()
|
|
ChatGptPool.Add()
|
|
- finalReply := If(lastData.Response != "", lastData.Response, g.Cfg().MustGet(m.Ctx, "limit.emptyMsg").String()).(string)
|
|
|
|
|
|
+ finalReply := If(isEmpty, g.Cfg().MustGet(m.Ctx, "limit.emptyMsg").String(), lastData.Response).(string)
|
|
replyId := ChatHistory.Save(m.Ctx, &ChatRecord{
|
|
replyId := ChatHistory.Save(m.Ctx, &ChatRecord{
|
|
Content: finalReply,
|
|
Content: finalReply,
|
|
Type: 2,
|
|
Type: 2,
|
|
- Actions: 1,
|
|
|
|
|
|
+ Actions: gconv.Int(If(isEmpty, 0, 1)),
|
|
QuestionId: questionId,
|
|
QuestionId: questionId,
|
|
PersonId: jSession.PositionId,
|
|
PersonId: jSession.PositionId,
|
|
Item: Answer_ChatGPT,
|
|
Item: Answer_ChatGPT,
|
|
CreateTime: time.Now().Format(date.Date_Full_Layout),
|
|
CreateTime: time.Now().Format(date.Date_Full_Layout),
|
|
})
|
|
})
|
|
- _ = ws.WriteJSON(g.Map{"error_code": 0, "error_msg": "", "data": g.Map{"id": encrypt.SE.Encode2Hex(fmt.Sprintf("%d", replyId)), "reply": finalReply, "isEnd": true}})
|
|
|
|
|
|
+ if !isEmpty {
|
|
|
|
+ _ = ws.WriteJSON(g.Map{"error_code": 0, "error_msg": "", "data": g.Map{"id": encrypt.SE.Encode2Hex(fmt.Sprintf("%d", replyId)), "reply": finalReply, "isEnd": true}})
|
|
|
|
+ } else {
|
|
|
|
+ _ = ws.WriteJSON(g.Map{"error_code": -1, "error_msg": finalReply})
|
|
|
|
+ }
|
|
break
|
|
break
|
|
}
|
|
}
|
|
if _, data := parseEventStream(line); data != nil {
|
|
if _, data := parseEventStream(line); data != nil {
|
|
|
|
+ isEmpty = false
|
|
data.Response = fsw.Repl(data.Response)
|
|
data.Response = fsw.Repl(data.Response)
|
|
lastData = data
|
|
lastData = data
|
|
_ = ws.WriteJSON(g.Map{"error_code": 0, "error_msg": "", "data": g.Map{"reply": lastData.Response, "isEnd": false}})
|
|
_ = ws.WriteJSON(g.Map{"error_code": 0, "error_msg": "", "data": g.Map{"reply": lastData.Response, "isEnd": false}})
|