feat: 支持结构化构建类型追加附件内容

This commit is contained in:
2026-06-29 17:17:02 +08:00
parent 6b58dd4cec
commit e981cc947b
+43
View File
@@ -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),