From b4ab058ee3097dfd8c7c1ee7a2c458b1d41f4e3f Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Mon, 12 May 2025 13:57:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BC=9A=E8=AF=9D=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=B6=88=E6=81=AF=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/im.go | 7 ++++++- proto/im.go | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/handler/im.go b/handler/im.go index 6efefba..3cda178 100644 --- a/handler/im.go +++ b/handler/im.go @@ -16,6 +16,7 @@ import ( "net/http" "strconv" "sync" + "time" ) type SMessage struct { @@ -133,6 +134,10 @@ func subscribeAndHandleIMMessages(ws *websocket.Conn, userId int) { err = doReceiveGenChatMessage(userId, &sessionID, &data, chanel) if err != nil { log.Println("do receive gen chat message error:", err) + //返回错误消息 + errMsg := proto.WSMessage{Code: proto.OperationFailed, ErrorMsg: "服务器处理错误", SessionID: int(sessionID)} + errMsgStr, _ := json.Marshal(errMsg) + worker.Publish(chanel, string(errMsgStr), time.Second*60) return } } @@ -236,7 +241,7 @@ func doReceiveGenChatMessage(userId int, sessionID *uint, data *proto.WSMessageR } log.Println("create session id:", *sessionID) //会话名称过长,使用ai进行总结 - if len(sessionName) > 30 { + if len(sessionName) > 30 && data.Function == "gen-chat" { //只有在通用聊天时才进行ai总结 //通过ai总结会话名称 go func() { sessionErr := service.UpdateSessionNameByAIAndID(int(*sessionID), userId, sessionName) diff --git a/proto/im.go b/proto/im.go index affc8b5..d50eea3 100644 --- a/proto/im.go +++ b/proto/im.go @@ -14,6 +14,7 @@ type AIQueueMessage struct { type WSMessage struct { Code int `json:"code"` //返回码,0表示成功, 其它状态码 Type string `json:"type"` //接收及发送消息类型 + ErrorMsg string `json:"error_msg"` //错误信息 Msg AIQueueMessage `json:"msg"` //消息内容,只进行转发,不做处理 SessionID int `json:"session_id"` //应用层会话id ToID int `json:"to_id"` //接收者id