结构修改
This commit is contained in:
parent
d277ce1afb
commit
6b9b4e992f
|
@ -73,7 +73,7 @@ func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRe
|
||||||
requireData.Ch = make(chan entitys.Response)
|
requireData.Ch = make(chan entitys.Response)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
// 启动独立的消息处理协程
|
// 启动独立的消息处理协程
|
||||||
done := r.startMessageHandler(ctx, c, &requireData)
|
done := r.startMessageHandler(ctx, c, &requireData, req.Text)
|
||||||
defer func() {
|
defer func() {
|
||||||
close(requireData.Ch) //关闭主通道
|
close(requireData.Ch) //关闭主通道
|
||||||
<-done // 等待消息处理完成
|
<-done // 等待消息处理完成
|
||||||
|
@ -113,6 +113,7 @@ func (r *AiRouterBiz) startMessageHandler(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
c *websocket.Conn,
|
c *websocket.Conn,
|
||||||
requireData *entitys.RequireData,
|
requireData *entitys.RequireData,
|
||||||
|
userInput string,
|
||||||
) <-chan struct{} {
|
) <-chan struct{} {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
var chat []string
|
var chat []string
|
||||||
|
@ -125,7 +126,7 @@ func (r *AiRouterBiz) startMessageHandler(
|
||||||
{
|
{
|
||||||
SessionID: requireData.Session,
|
SessionID: requireData.Session,
|
||||||
Role: "user",
|
Role: "user",
|
||||||
Content: "", // 用户输入在外部处理
|
Content: userInput, // 用户输入在外部处理
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if len(chat) > 0 {
|
if len(chat) > 0 {
|
||||||
|
|
|
@ -62,6 +62,7 @@ func (s *SessionBiz) SessionInit(ctx context.Context, req *entitys.SessionInitRe
|
||||||
SysID: sysConfig.SysID,
|
SysID: sysConfig.SysID,
|
||||||
SessionID: utils.UUID(),
|
SessionID: utils.UUID(),
|
||||||
UserID: req.UserId,
|
UserID: req.UserId,
|
||||||
|
UserName: req.UserName,
|
||||||
}
|
}
|
||||||
err = s.sessionRepo.Create(&session)
|
err = s.sessionRepo.Create(&session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -21,6 +21,7 @@ type AiSession struct {
|
||||||
Status int32 `gorm:"column:status;not null" json:"status"`
|
Status int32 `gorm:"column:status;not null" json:"status"`
|
||||||
DeleteAt *time.Time `gorm:"column:delete_at" json:"delete_at"`
|
DeleteAt *time.Time `gorm:"column:delete_at" json:"delete_at"`
|
||||||
UserID string `gorm:"column:user_id;comment:用户id" json:"user_id"` // 用户id
|
UserID string `gorm:"column:user_id;comment:用户id" json:"user_id"` // 用户id
|
||||||
|
UserName string `gorm:"column:user_name;comment:用户名称" json:"user_name"` // 用户id
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName AiSession's table name
|
// TableName AiSession's table name
|
||||||
|
|
|
@ -3,6 +3,7 @@ package entitys
|
||||||
type SessionInitRequest struct {
|
type SessionInitRequest struct {
|
||||||
SysId string `json:"sys_id"`
|
SysId string `json:"sys_id"`
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
|
UserName string `json:"user_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionInitResponse struct {
|
type SessionInitResponse struct {
|
||||||
|
|
Loading…
Reference in New Issue