From e981cc947b42d5f70e87163282c357fc0472d4ea Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Mon, 29 Jun 2026 17:17:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=8C=96=E6=9E=84=E5=BB=BA=E7=B1=BB=E5=9E=8B=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/prompt/prompt_build_service.go | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/service/prompt/prompt_build_service.go b/service/prompt/prompt_build_service.go index 2822bfb..36a88fd 100644 --- a/service/prompt/prompt_build_service.go +++ b/service/prompt/prompt_build_service.go @@ -3,6 +3,7 @@ package prompt import ( "context" "fmt" + "prompts-core/consts/public" "prompts-core/service/gateway" "strings" @@ -13,6 +14,7 @@ import ( "gitea.redpowerfuture.com/red-future/common/utils" "github.com/gogf/gf/v2/encoding/gjson" + "github.com/gogf/gf/v2/util/gconv" ) // buildPromptTypeRequest 构建提示词类型请求(BuildType=1) @@ -63,6 +65,47 @@ func compileToProviderRequest(ctx context.Context, ir *IR, chatModel *gateway.As if err != nil { return nil, fmt.Errorf("编译请求失败: %w", err) } + + if req.BuildType == public.BuildTypeStruct && len(req.Consult) > 0 { + msgs, _ := providerReq["messages"].([]map[string]any) + templates := gconv.Map(chatModel.ExtendMapping["attachment_templates"]) + + for i, msg := range msgs { + if msg["role"] != "user" { + continue + } + // 保持原有 content + var content []map[string]any + switch c := msg["content"].(type) { + case []map[string]any: + content = c + case string: + content = []map[string]any{{"type": "text", "text": c}} + default: + continue + } + // 追加附件 + for _, item := range req.Consult { + tmpl := gconv.Map(templates[item.Type]) + if len(tmpl) == 0 { + continue + } + body := gconv.Map(tmpl["body"]) + for k, v := range body { + if s, ok := v.(string); ok && s == "" { + body[k] = item.Url + } + } + content = append(content, map[string]any{ + "type": tmpl["type"], + tmpl["type"].(string): body, + }) + } + msgs[i]["content"] = content + } + providerReq["messages"] = msgs + } + return map[string]any{ "modelName": chatModel.ModelName, "bizName": util.GetServerName(ctx),