feat(session): 重构会话管理和Redis缓存机制

This commit is contained in:
2026-06-09 14:00:01 +08:00
parent 1f9a2b9b5f
commit 9410199fbe
8 changed files with 324 additions and 196 deletions

View File

@@ -198,13 +198,10 @@ func handleCallbackSuccess(ctx context.Context, req *dto.CallbackReq, composeTas
buildType := gconv.Int(payload["buildType"])
if buildType == public.BuildTypePrompt && sessionId != "" && nodeId != "" {
// 4) 获取历史内容并拼接
history, _ := session.GetHistoryMessages(ctx, sessionId, nodeId)
for _, msg := range history {
role := gconv.String(msg["role"])
if role != "user" && role != "assistant" {
continue
}
}
_, _ = session.GetHistoryMessages(ctx, &dto.GetHistoryMessagesReq{
SessionId: sessionId,
NodeId: nodeId,
})
// 5) 存储提示词结果作为历史请求
if userMsg := util.ExtractUserText(messages); userMsg != nil {
epicycleId, err = dao.ComposeSession.Insert(ctx, &entity.ComposeSession{
@@ -261,11 +258,15 @@ func parseMessagesForResponse(messages any) any {
}
func GetPromptText(ctx context.Context, req *dto.GetPromptTextReq) (*dto.GetPromptTextRes, error) {
// 1) 获取基础数据
// 4) 模拟历史拼接
history, _ := session.GetHistoryMessages(ctx, "88888888", "node1")
history, err := session.GetHistoryMessages(ctx, &dto.GetHistoryMessagesReq{
SessionId: "88888888",
NodeId: "node1",
})
if err != nil {
return nil, err
}
return &dto.GetPromptTextRes{
Messages: history,
Messages: history.Messages,
}, nil
}