topfans/backend/gateway/service/laser_prompt.go
2026-06-03 22:19:22 +08:00

70 lines
3.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"strings"
)
// ──────────────────────────────────────────────
// 镭射卡 prompt 构建规范
//
// 调用结构:
// 调用 1 (背景图 bg)[前缀_bg] + [主题描述] + [用户注入] + [负向约束]
// 调用 2 (装饰图 ol)[前缀_ol] + [主题描述] + [用户注入] + [负向约束]
//
// 前缀/后缀由本文件硬编码,确保所有 prompt 输出受控。
// 主题描述来自前端 laserPresets.js 的 bgPrompt/overlayPrompt。
// 用户注入来自前端的 user_prompt 字段。
// ──────────────────────────────────────────────
// ── 前缀(技术性约束 + 镭射卡美学指引,固定加在最前) ──
const bgPrefix = "高端镭射明星小卡背景图3:4竖版构图。核心要素金属镭射质感、全息衍射光泽、彩虹色散光晕像光在CD表面折射出的梦幻色彩。可以是抽象渐变流体、镭射光斑散景、全息薄膜纹理或极光般流动色带。画面要有纵深感和丰富的色彩层次银底基调上叠加主题色。禁止出现人物人脸。"
const overlayPrefix = "高端镭射装饰元素图3:4竖版白底装饰之外的区域必须为纯白色(#FFFFFF)。装饰风格自由发挥——可以是流光溢彩的光轨线条、镭射星芒和光晕粒子、精致的手绘花纹边框、全息几何图案、碎钻般亮点散布,或以上任意组合。核心要求:元素要有镭射般的七彩闪耀质感,疏密有致不过于拥挤,整体精致高级不廉价。禁止出现人物人脸。"
// ── 后缀(负向词,固定加在最后) ──
const negativeSuffix = "禁止出现如下内容文字、字母、数字、水印、logo、签名、人物、人脸、边框线框、二维码、条形码"
// ── 用户注入模版 ──
const userInjectionTemplate = "。同时在画面中自然融入以下视觉元素:" // userPrompt 非空时追加
// BuildBgPrompt 将系统前缀 + 主题描述 + 用户内容 + 负向词拼接为最终背景图 prompt
func BuildBgPrompt(templateBody, userPrompt string) string {
return buildPrompt(bgPrefix, templateBody, userPrompt)
}
// BuildOverlayPrompt 将系统前缀 + 主题描述 + 用户内容 + 负向词拼接为最终装饰图 prompt
func BuildOverlayPrompt(templateBody, userPrompt string) string {
return buildPrompt(overlayPrefix, templateBody, userPrompt)
}
// buildPrompt 通用拼接
func buildPrompt(prefix, body, userPrompt string) string {
var b strings.Builder
// 1. 前缀(技术约束)
b.WriteString(prefix)
// 2. 主题描述(中间核心内容)
if body = strings.TrimSpace(body); body != "" {
if b.Len() > 0 && !strings.HasSuffix(b.String(), "。") {
b.WriteString("。")
}
b.WriteString(body)
}
// 3. 用户注入(可选)
if user := strings.TrimSpace(userPrompt); user != "" {
b.WriteString(userInjectionTemplate)
b.WriteString(user)
}
// 4. 后缀(负向约束)
b.WriteString("。")
b.WriteString(negativeSuffix)
return b.String()
}