Merge branch 'refs/heads/feat-ai-session-name'

This commit is contained in:
junleea 2025-05-12 13:57:45 +08:00
commit 623a590b2d
2 changed files with 7 additions and 1 deletions

View File

@ -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)

View File

@ -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