feat: 新增配置与提示词偏好页
后端新增 preferences 与 prompt_customizations 表及对应接口, 支持 BYOK 模型渠道密钥落库(仅回显掩码)与按任务类型定制 平台提示词模板;前端新增 /settings 页面及入口。
This commit is contained in:
1 parent
ae6cdf1551
commit
b9df2f84ab
27 files changed
+1515
-22
No files matched your search
@@ -0,0 +1,219 @@
|
||||
// Package prompts 维护平台内置的提示词模板目录。
|
||||
//
|
||||
// 结构与 open-ai-canvas 的 internal/prompts 对齐:
|
||||
// 任务类型(operation)+ 平台默认模板(DefaultContent)+ 用户定制模式(inherit / append / rewrite)。
|
||||
// 本项目暂不提供管理后台,平台模板直接内置在代码里,不落库;落库的只有用户定制。
|
||||
package prompts
|
||||
|
||||
// 内置任务类型。新增或改名时同步维护 web/src/types/prompt.ts。
|
||||
const (
|
||||
OperationTextToImage = "text_to_image"
|
||||
OperationReferenceImage = "reference_image"
|
||||
OperationTextToVideo = "text_to_video"
|
||||
OperationImageToVideo = "image_to_video"
|
||||
OperationTextToAudio = "text_to_audio"
|
||||
OperationPromptEnhance = "prompt_enhance"
|
||||
)
|
||||
|
||||
// TemplateVersion 平台模板版本。**修改任一 DefaultContent 后必须递增**,
|
||||
// 基于旧版本做过定制的用户会在界面上看到「平台模板已更新」提示。
|
||||
const TemplateVersion = 1
|
||||
|
||||
// Variable 模板里可被替换的占位符,供前端提示可用变量。
|
||||
type Variable struct {
|
||||
Label string `json:"label"`
|
||||
Placeholder string `json:"placeholder"`
|
||||
}
|
||||
|
||||
// Definition 一个任务类型的元信息。
|
||||
type Definition struct {
|
||||
Operation string `json:"operation"`
|
||||
Label string `json:"label"`
|
||||
Category string `json:"category"`
|
||||
Description string `json:"description"`
|
||||
OutputType string `json:"outputType"`
|
||||
Variables []Variable `json:"variables"`
|
||||
|
||||
// DefaultContent 平台默认模板,只用于后端组装响应,不随目录整体下发。
|
||||
DefaultContent string `json:"-"`
|
||||
}
|
||||
|
||||
// Definitions 返回全部内置任务类型,顺序即前端展示顺序。
|
||||
func Definitions() []Definition {
|
||||
return []Definition{
|
||||
{
|
||||
Operation: OperationTextToImage,
|
||||
Label: "文生图",
|
||||
Category: "图片",
|
||||
Description: "把文本提示词整理成图片模型的执行提示词。",
|
||||
OutputType: "text",
|
||||
Variables: []Variable{
|
||||
{Label: "主体描述", Placeholder: "{{主体描述}}"},
|
||||
{Label: "画面风格", Placeholder: "{{画面风格}}"},
|
||||
{Label: "构图与镜头", Placeholder: "{{构图与镜头}}"},
|
||||
{Label: "光线与色调", Placeholder: "{{光线与色调}}"},
|
||||
{Label: "负面要求", Placeholder: "{{负面要求}}"},
|
||||
},
|
||||
DefaultContent: `生成一张单一、可执行的画面。只描述静止图像,不写后续运动。明确主体、环境与视觉焦点,写清前中后景关系、遮挡与材质表现,不添加未要求的人物、文字或水印。
|
||||
|
||||
【主体描述】
|
||||
{{主体描述}}
|
||||
|
||||
【画面风格】
|
||||
{{画面风格}}
|
||||
|
||||
【构图与镜头】
|
||||
{{构图与镜头}}
|
||||
|
||||
【光线与色调】
|
||||
{{光线与色调}}
|
||||
|
||||
【负面要求】
|
||||
{{负面要求}}`,
|
||||
},
|
||||
{
|
||||
Operation: OperationReferenceImage,
|
||||
Label: "参考图生成",
|
||||
Category: "图片",
|
||||
Description: "在参考图基础上生成新画面,写清要改什么、要保留什么。",
|
||||
OutputType: "text",
|
||||
Variables: []Variable{
|
||||
{Label: "参考图说明", Placeholder: "{{参考图说明}}"},
|
||||
{Label: "目标修改", Placeholder: "{{目标修改}}"},
|
||||
{Label: "需要保持", Placeholder: "{{需要保持}}"},
|
||||
{Label: "负面要求", Placeholder: "{{负面要求}}"},
|
||||
},
|
||||
DefaultContent: `基于参考图生成新画面。先锁定必须保持不变的部分,再描述需要改变的部分;改动范围之外的构图、身份、服装与材质不要自行改写。
|
||||
|
||||
【参考图说明】
|
||||
{{参考图说明}}
|
||||
|
||||
【目标修改】
|
||||
{{目标修改}}
|
||||
|
||||
【需要保持】
|
||||
{{需要保持}}
|
||||
|
||||
【负面要求】
|
||||
{{负面要求}}`,
|
||||
},
|
||||
{
|
||||
Operation: OperationTextToVideo,
|
||||
Label: "文生视频",
|
||||
Category: "视频",
|
||||
Description: "把文本提示词整理成视频模型的执行提示词。",
|
||||
OutputType: "text",
|
||||
Variables: []Variable{
|
||||
{Label: "主体描述", Placeholder: "{{主体描述}}"},
|
||||
{Label: "镜头运动", Placeholder: "{{镜头运动}}"},
|
||||
{Label: "时间节拍", Placeholder: "{{时间节拍}}"},
|
||||
{Label: "氛围与光线", Placeholder: "{{氛围与光线}}"},
|
||||
{Label: "负面要求", Placeholder: "{{负面要求}}"},
|
||||
},
|
||||
DefaultContent: `生成单一连续镜头。一个镜头只保留一个叙事目标、一个主运镜和一条主要动作链;摄影机运动必须有起点、动机和停止点。优先保证主体身份、关键动作和连续性,次要环境效果可以简化。
|
||||
|
||||
【主体描述】
|
||||
{{主体描述}}
|
||||
|
||||
【镜头运动】
|
||||
{{镜头运动}}
|
||||
|
||||
【时间节拍】
|
||||
{{时间节拍}}
|
||||
|
||||
【氛围与光线】
|
||||
{{氛围与光线}}
|
||||
|
||||
【负面要求】
|
||||
{{负面要求}}`,
|
||||
},
|
||||
{
|
||||
Operation: OperationImageToVideo,
|
||||
Label: "图生视频",
|
||||
Category: "视频",
|
||||
Description: "以首帧图片为起点驱动视频,专注运动与调度。",
|
||||
OutputType: "text",
|
||||
Variables: []Variable{
|
||||
{Label: "首帧说明", Placeholder: "{{首帧说明}}"},
|
||||
{Label: "运动与调度", Placeholder: "{{运动与调度}}"},
|
||||
{Label: "镜头运动", Placeholder: "{{镜头运动}}"},
|
||||
{Label: "时间节拍", Placeholder: "{{时间节拍}}"},
|
||||
{Label: "负面要求", Placeholder: "{{负面要求}}"},
|
||||
},
|
||||
DefaultContent: `以给定首帧为起点生成单一连续镜头。构图、主体身份、服装与光线严格继承首帧,只描述首帧之后的运动与调度,不重新设计画面。
|
||||
|
||||
【首帧说明】
|
||||
{{首帧说明}}
|
||||
|
||||
【运动与调度】
|
||||
{{运动与调度}}
|
||||
|
||||
【镜头运动】
|
||||
{{镜头运动}}
|
||||
|
||||
【时间节拍】
|
||||
{{时间节拍}}
|
||||
|
||||
【负面要求】
|
||||
{{负面要求}}`,
|
||||
},
|
||||
{
|
||||
Operation: OperationTextToAudio,
|
||||
Label: "音频生成",
|
||||
Category: "音频",
|
||||
Description: "把文本整理成配音或音效的生成提示词。",
|
||||
OutputType: "text",
|
||||
Variables: []Variable{
|
||||
{Label: "内容与情绪", Placeholder: "{{内容与情绪}}"},
|
||||
{Label: "音色与语速", Placeholder: "{{音色与语速}}"},
|
||||
{Label: "时长与节奏", Placeholder: "{{时长与节奏}}"},
|
||||
{Label: "负面要求", Placeholder: "{{负面要求}}"},
|
||||
},
|
||||
DefaultContent: `生成一段可直接使用的音频。发音清晰、断句自然,情绪与内容一致,不添加未要求的背景音乐或旁白。
|
||||
|
||||
【内容与情绪】
|
||||
{{内容与情绪}}
|
||||
|
||||
【音色与语速】
|
||||
{{音色与语速}}
|
||||
|
||||
【时长与节奏】
|
||||
{{时长与节奏}}
|
||||
|
||||
【负面要求】
|
||||
{{负面要求}}`,
|
||||
},
|
||||
{
|
||||
Operation: OperationPromptEnhance,
|
||||
Label: "提示词扩写",
|
||||
Category: "通用",
|
||||
Description: "把简短想法扩写为可直接投喂模型的提示词。",
|
||||
OutputType: "text",
|
||||
Variables: []Variable{
|
||||
{Label: "用户原始想法", Placeholder: "{{用户原始想法}}"},
|
||||
{Label: "目标模型", Placeholder: "{{目标模型}}"},
|
||||
{Label: "补充约束", Placeholder: "{{补充约束}}"},
|
||||
},
|
||||
DefaultContent: `你是一位提示词工程师。把用户的简短想法扩写为可直接投喂模型的提示词:保留原意,补齐主体、环境、构图、光线与材质等可执行细节,不添加用户未要求的元素,不解释你的改写过程,只输出提示词本身。
|
||||
|
||||
【用户原始想法】
|
||||
{{用户原始想法}}
|
||||
|
||||
【目标模型】
|
||||
{{目标模型}}
|
||||
|
||||
【补充约束】
|
||||
{{补充约束}}`,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Find 按任务类型查定义。
|
||||
func Find(operation string) (Definition, bool) {
|
||||
for _, definition := range Definitions() {
|
||||
if definition.Operation == operation {
|
||||
return definition, true
|
||||
}
|
||||
}
|
||||
return Definition{}, false
|
||||
}
|
||||
Reference in new issue
Block a user