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