From 733f0429fef0109cf7ba294573f7bf7e2f2c3f9a Mon Sep 17 00:00:00 2001 From: WangLiZhao <1838393649@qq.com> Date: Mon, 22 Jun 2026 15:08:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor(gateway):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=9B=9E=E8=B0=83=E5=92=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/dto/prompt_session_dto.go | 8 ++++-- service/prompt/prompt_compose_service.go | 6 +++-- service/session/prompt_session_service.go | 30 ++++++++++++++++++++--- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/model/dto/prompt_session_dto.go b/model/dto/prompt_session_dto.go index 5b1ea87..6b585a7 100644 --- a/model/dto/prompt_session_dto.go +++ b/model/dto/prompt_session_dto.go @@ -16,8 +16,12 @@ type HistoryRound struct { // SessionCallbackReq 会话回调请求 type SessionCallbackReq struct { g.Meta `path:"/callback" method:"post" tags:"会话管理" summary:"会话回调"` - Messages map[string]any `json:"messages" v:"required" dc:"消息数组"` - EpicycleId int64 `json:"epicycleId" v:"required" dc:"轮次ID"` + EpicycleId int64 `json:"epicycleId"` + TaskId string `json:"task_id"` + State int `json:"state"` + ErrorMsg string `json:"error_msg"` + OssFile string `json:"oss_file"` + FileType string `json:"file_type"` } // SessionCallbackRes 会话回调响应 diff --git a/service/prompt/prompt_compose_service.go b/service/prompt/prompt_compose_service.go index 2d62162..2cc196e 100644 --- a/service/prompt/prompt_compose_service.go +++ b/service/prompt/prompt_compose_service.go @@ -2,6 +2,7 @@ package prompt import ( "context" + "encoding/json" "errors" "fmt" "prompts-core/common/util" @@ -14,7 +15,6 @@ import ( "gitea.redpowerfuture.com/red-future/common/beans" "gitea.redpowerfuture.com/red-future/common/utils" - "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/util/gconv" ) @@ -154,7 +154,9 @@ func Callback(ctx context.Context, req *dto.CallbackReq) error { // 3) 解析 OSS 内容为消息 var messages map[string]any if len(ossContent) > 0 { - messages = gjson.New(ossContent).Map() + if err := json.Unmarshal(ossContent, &messages); err != nil { + g.Log().Warningf(ctx, "[回调处理] 解析OSS内容失败 taskId=%s err=%v", req.TaskId, err) + } } // 4) 处理失败 diff --git a/service/session/prompt_session_service.go b/service/session/prompt_session_service.go index 4271aff..b93216e 100644 --- a/service/session/prompt_session_service.go +++ b/service/session/prompt_session_service.go @@ -2,7 +2,9 @@ package session import ( "context" + "encoding/json" "fmt" + "prompts-core/service/gateway" "gitea.redpowerfuture.com/red-future/common/beans" "gitea.redpowerfuture.com/red-future/common/utils" @@ -21,11 +23,31 @@ import ( // Callback 会话回调 func Callback(ctx context.Context, req *dto.SessionCallbackReq) (*dto.SessionCallbackRes, error) { - req.Messages["role"] = "assistant" + // 1) 读取 OSS 文件内容 + var ( + ossContent []byte + messages map[string]any + err error + ) + if req.OssFile != "" { + ossContent, err = gateway.GetFileBytesFromURL(ctx, req.OssFile) + if err != nil { + g.Log().Infof(ctx, "[会话回调] 读取OSS文件 taskId=%s,state=%v,ossFile=%v", req.TaskId, req.State, req.OssFile) + g.Log().Warningf(ctx, "[会话回调] 读取OSS失败 taskId=%s err=%v", req.TaskId, err) + } + } + + // 3) 解析 OSS 内容为消息 + if len(ossContent) > 0 { + if err := json.Unmarshal(ossContent, &messages); err != nil { + g.Log().Warningf(ctx, "[回调处理] 解析OSS内容失败 taskId=%s err=%v", req.TaskId, err) + } + } + messages["role"] = "assistant" // 1) 更新 DB - _, err := dao.ComposeSession.Update(ctx, &entity.ComposeSession{ + _, err = dao.ComposeSession.Update(ctx, &entity.ComposeSession{ SQLBaseDO: beans.SQLBaseDO{Id: req.EpicycleId}, - ResponseContent: req.Messages, + ResponseContent: messages, }) if err != nil { g.Log().Errorf(ctx, "[会话回调] 更新数据库失败 epicycleId=%d err=%v", req.EpicycleId, err) @@ -42,7 +64,7 @@ func Callback(ctx context.Context, req *dto.SessionCallbackReq) (*dto.SessionCal // 3) entity → HistoryRound → 写入 Redis round := entityToHistoryRound(session) - round.Assistant = req.Messages + round.Assistant = messages if err = SaveToRedis(ctx, session.TenantId, session.SessionId, session.NodeId, round); err != nil { return nil, fmt.Errorf("redis存储失败: %w", err) }