diff --git a/common/util/mapping.go b/common/util/mapping.go index 821e183..11be623 100644 --- a/common/util/mapping.go +++ b/common/util/mapping.go @@ -1,6 +1,7 @@ package util import ( + "encoding/json" "fmt" "strings" @@ -114,27 +115,16 @@ func buildAttachment(tmpl map[string]any, url string) map[string]any { return nil } - body := gconv.Map(tmpl["body"]) - fillEmptyInPlace(body, url) + // 深拷贝模板 + b, _ := json.Marshal(tmpl) + str := string(b) + str = strings.ReplaceAll(str, `"{{url}}"`, `"`+url+`"`) - return map[string]any{ - "type": typ, - typ: body, - } -} - -// fillEmptyInPlace 递归填充空字符串 -func fillEmptyInPlace(m map[string]any, value string) { - for k, v := range m { - switch vv := v.(type) { - case string: - if vv == "" { - m[k] = value - } - case map[string]any: - fillEmptyInPlace(vv, value) - } - } + var result map[string]any + _ = json.Unmarshal([]byte(str), &result) + delete(result, "type") + result["type"] = typ + return result } // ======================== 系统提示词合并 ======================== diff --git a/service/prompt/prompt_compose_service.go b/service/prompt/prompt_compose_service.go index 2cc196e..6a43411 100644 --- a/service/prompt/prompt_compose_service.go +++ b/service/prompt/prompt_compose_service.go @@ -129,8 +129,7 @@ func handleBuild(ctx context.Context, req *dto.ComposeMessagesReq, chatModel, ai // Callback 回调处理 func Callback(ctx context.Context, req *dto.CallbackReq) error { - g.Log().Infof(ctx, "[开始回调处理] taskId=%s state=%d", req.TaskId, req.State) - + g.Log().Infof(ctx, "[开始回调处理] taskId=%s state=%d ossFile=%s", req.TaskId, req.State, req.OssFile) // 1) 查询任务 composeTask, err := dao.ComposeTask.Get(ctx, &entity.ComposeTask{TaskId: req.TaskId}) if err != nil { @@ -154,7 +153,7 @@ func Callback(ctx context.Context, req *dto.CallbackReq) error { // 3) 解析 OSS 内容为消息 var messages map[string]any if len(ossContent) > 0 { - if err := json.Unmarshal(ossContent, &messages); err != nil { + if err = json.Unmarshal(ossContent, &messages); err != nil { g.Log().Warningf(ctx, "[回调处理] 解析OSS内容失败 taskId=%s err=%v", req.TaskId, err) } } @@ -240,6 +239,9 @@ func handleCallbackSuccess(ctx context.Context, req *dto.CallbackReq, composeTas userPrompt := composeTask.RequestPayload["userPrompt"].(string) messages = util.MergeSystemPrompt(messages, systemPrompt, skillContent, userPrompt, model.RequestMapping) + fmt.Println("打印1", composeTask.RequestPayload) + fmt.Println("打印2", messages) + fmt.Println("打印3", model.ExtendMapping) // 5) 合并附加结构 messages = util.MergeConsult(composeTask.RequestPayload, messages, model.ExtendMapping) // 6) 注入历史