修改生成视频提示词api单个传入
This commit is contained in:
parent
68f2c62c46
commit
9158783918
@ -9,53 +9,49 @@ export default router.post(
|
|||||||
"/",
|
"/",
|
||||||
validateFields({
|
validateFields({
|
||||||
projectId: z.number(),
|
projectId: z.number(),
|
||||||
storyboardIds: z.array(z.number()),
|
storyboardId: z.number(),
|
||||||
}),
|
}),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { projectId, storyboardIds } = req.body;
|
const { projectId, storyboardId } = req.body;
|
||||||
|
|
||||||
// 查询分镜及其关联的资产提示词
|
// 查询分镜及其关联的资产提示词
|
||||||
const data = await u
|
const data = await u
|
||||||
.db("o_storyboard")
|
.db("o_storyboard")
|
||||||
.leftJoin("o_assets2Storyboard", "o_storyboard.id", "o_assets2Storyboard.storyboardId")
|
.leftJoin("o_assets2Storyboard", "o_storyboard.id", "o_assets2Storyboard.storyboardId")
|
||||||
.leftJoin("o_assets", "o_assets2Storyboard.assetId", "o_assets.id")
|
.leftJoin("o_assets", "o_assets2Storyboard.assetId", "o_assets.id")
|
||||||
.leftJoin("o_videoConfig", "o_storyboard.id", "o_videoConfig.storyboardId")
|
.leftJoin("o_videoConfig", "o_storyboard.id", "o_videoConfig.storyboardId")
|
||||||
.whereIn("o_storyboard.id", storyboardIds)
|
.where("o_storyboard.id", storyboardId)
|
||||||
.select("o_storyboard.id", "o_storyboard.prompt", "o_assets.prompt as assetPrompt", "o_videoConfig.model as videoModel");
|
.select("o_storyboard.id", "o_storyboard.prompt", "o_assets.prompt as assetPrompt", "o_videoConfig.model as videoModel");
|
||||||
|
|
||||||
// 按分镜id分组,聚合资产提示词
|
if (data.length === 0) {
|
||||||
const storyboardMap = new Map<number, { prompt: string; assetPrompts: string[]; videoModel: string }>();
|
return res.status(200).send(success({ data: null }));
|
||||||
for (const row of data) {
|
|
||||||
if (!storyboardMap.has(row.id)) {
|
|
||||||
storyboardMap.set(row.id, { prompt: row.prompt || "", assetPrompts: [], videoModel: row.videoModel || "" });
|
|
||||||
}
|
|
||||||
if (row.assetPrompt) {
|
|
||||||
storyboardMap.get(row.id)!.assetPrompts.push(row.assetPrompt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 逐个分镜生成视频提示词
|
// 聚合资产提示词
|
||||||
const results: { storyboardId: number; videoPrompt: string }[] = [];
|
const prompt = data[0].prompt || "";
|
||||||
for (const [id, { prompt, assetPrompts, videoModel }] of storyboardMap) {
|
const videoModel = data[0].videoModel || "";
|
||||||
let model = "";
|
const assetPrompts = data.map((row) => row.assetPrompt).filter(Boolean) as string[];
|
||||||
if (videoModel) {
|
|
||||||
model = videoModel;
|
|
||||||
} else {
|
|
||||||
const videoModel = await u.db("o_project").where("id", projectId).select("videoModel").first();
|
|
||||||
model = videoModel?.videoModel || "";
|
|
||||||
}
|
|
||||||
if (!model) continue; //分镜没有指定视频模型,且项目也没有默认视频模型,跳过生成提示词
|
|
||||||
const systemPrompt = `你是一个专业的${model}视频生成助手。请根据分镜提示词和关联资产提示词,生成一段完整的、可直接用于视频生成模型的中文提示词。`;
|
|
||||||
const userContent = `分镜提示词:${prompt || "无"}\n资产提示词:${assetPrompts.length > 0 ? assetPrompts.join("\n") : "无"}`;
|
|
||||||
|
|
||||||
const { text } = await u.Ai.Text("universalAi").invoke({
|
// 确定视频模型
|
||||||
system: systemPrompt,
|
let model = videoModel;
|
||||||
messages: [{ role: "user", content: userContent }],
|
if (!model) {
|
||||||
});
|
const project = await u.db("o_project").where("id", projectId).select("videoModel").first();
|
||||||
|
model = project?.videoModel || "";
|
||||||
await u.db("o_storyboard").where("id", id).update({ videoPrompt: text });
|
}
|
||||||
results.push({ storyboardId: id, videoPrompt: text });
|
if (!model) {
|
||||||
|
return res.status(200).send(success({ data: null }));
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).send(success({ data: results }));
|
const systemPrompt = `你是一个专业的${model}视频生成助手。请根据分镜提示词和关联资产提示词,生成一段完整的、可直接用于视频生成模型的中文提示词。`;
|
||||||
|
const userContent = `分镜提示词:${prompt || "无"}\n资产提示词:${assetPrompts.length > 0 ? assetPrompts.join("\n") : "无"}`;
|
||||||
|
|
||||||
|
const { text } = await u.Ai.Text("universalAi").invoke({
|
||||||
|
system: systemPrompt,
|
||||||
|
messages: [{ role: "user", content: userContent }],
|
||||||
|
});
|
||||||
|
|
||||||
|
await u.db("o_storyboard").where("id", storyboardId).update({ videoPrompt: text });
|
||||||
|
|
||||||
|
res.status(200).send(success({ data: { storyboardId, videoPrompt: text } }));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
62
src/types/database.d.ts
vendored
62
src/types/database.d.ts
vendored
@ -1,13 +1,62 @@
|
|||||||
// @db-hash 93b2462070c45c2b449e9a18c4e88763
|
// @db-hash ea0c51ccb8c93a2f019139db9621721e
|
||||||
//该文件由脚本自动生成,请勿手动修改
|
//该文件由脚本自动生成,请勿手动修改
|
||||||
|
|
||||||
|
export interface _o_project_old_20260330 {
|
||||||
|
'artStyle'?: string | null;
|
||||||
|
'createTime'?: number | null;
|
||||||
|
'id'?: number | null;
|
||||||
|
'intro'?: string | null;
|
||||||
|
'name'?: string | null;
|
||||||
|
'projectType'?: string | null;
|
||||||
|
'type'?: string | null;
|
||||||
|
'userId'?: number | null;
|
||||||
|
'videoRatio'?: string | null;
|
||||||
|
}
|
||||||
|
export interface _o_storyboard_old_20260325 {
|
||||||
|
'camera'?: string | null;
|
||||||
|
'createTime'?: number | null;
|
||||||
|
'description'?: string | null;
|
||||||
|
'duration'?: string | null;
|
||||||
|
'filePath'?: string | null;
|
||||||
|
'frameMode'?: string | null;
|
||||||
|
'id'?: number;
|
||||||
|
'lines'?: string | null;
|
||||||
|
'mode'?: string | null;
|
||||||
|
'model'?: string | null;
|
||||||
|
'prompt'?: string | null;
|
||||||
|
'reason'?: string | null;
|
||||||
|
'resolution'?: string | null;
|
||||||
|
'scriptId'?: number | null;
|
||||||
|
'sound'?: string | null;
|
||||||
|
'state'?: string | null;
|
||||||
|
'title'?: string | null;
|
||||||
|
}
|
||||||
|
export interface _o_storyboard_old_20260330 {
|
||||||
|
'camera'?: string | null;
|
||||||
|
'createTime'?: number | null;
|
||||||
|
'description'?: string | null;
|
||||||
|
'duration'?: string | null;
|
||||||
|
'filePath'?: string | null;
|
||||||
|
'frameMode'?: string | null;
|
||||||
|
'id'?: number;
|
||||||
|
'index'?: string | null;
|
||||||
|
'lines'?: string | null;
|
||||||
|
'mode'?: string | null;
|
||||||
|
'model'?: string | null;
|
||||||
|
'prompt'?: string | null;
|
||||||
|
'reason'?: string | null;
|
||||||
|
'resolution'?: string | null;
|
||||||
|
'scriptId'?: number | null;
|
||||||
|
'sound'?: string | null;
|
||||||
|
'state'?: string | null;
|
||||||
|
'title'?: string | null;
|
||||||
|
}
|
||||||
export interface memories {
|
export interface memories {
|
||||||
'content': string;
|
'content': string;
|
||||||
'createTime': number;
|
'createTime': number;
|
||||||
'embedding'?: string | null;
|
'embedding'?: string | null;
|
||||||
'id'?: string;
|
'id'?: string;
|
||||||
'isolationKey': string;
|
'isolationKey': string;
|
||||||
'name'?: string | null;
|
|
||||||
'relatedMessageIds'?: string | null;
|
'relatedMessageIds'?: string | null;
|
||||||
'role'?: string | null;
|
'role'?: string | null;
|
||||||
'summarized'?: number | null;
|
'summarized'?: number | null;
|
||||||
@ -47,7 +96,6 @@ export interface o_assets {
|
|||||||
'name'?: string | null;
|
'name'?: string | null;
|
||||||
'projectId'?: number | null;
|
'projectId'?: number | null;
|
||||||
'prompt'?: string | null;
|
'prompt'?: string | null;
|
||||||
'promptState'?: string | null;
|
|
||||||
'remark'?: string | null;
|
'remark'?: string | null;
|
||||||
'scriptId'?: number | null;
|
'scriptId'?: number | null;
|
||||||
'startTime'?: number | null;
|
'startTime'?: number | null;
|
||||||
@ -129,8 +177,6 @@ export interface o_prompt {
|
|||||||
export interface o_script {
|
export interface o_script {
|
||||||
'content'?: string | null;
|
'content'?: string | null;
|
||||||
'createTime'?: number | null;
|
'createTime'?: number | null;
|
||||||
'errorReason'?: string | null;
|
|
||||||
'extractState'?: number | null;
|
|
||||||
'id'?: number;
|
'id'?: number;
|
||||||
'name'?: string | null;
|
'name'?: string | null;
|
||||||
'projectId'?: number | null;
|
'projectId'?: number | null;
|
||||||
@ -167,7 +213,7 @@ export interface o_storyboard {
|
|||||||
'filePath'?: string | null;
|
'filePath'?: string | null;
|
||||||
'frameMode'?: string | null;
|
'frameMode'?: string | null;
|
||||||
'id'?: number;
|
'id'?: number;
|
||||||
'index'?: number | null;
|
'index'?: string | null;
|
||||||
'lines'?: string | null;
|
'lines'?: string | null;
|
||||||
'mode'?: string | null;
|
'mode'?: string | null;
|
||||||
'model'?: string | null;
|
'model'?: string | null;
|
||||||
@ -178,6 +224,7 @@ export interface o_storyboard {
|
|||||||
'sound'?: string | null;
|
'sound'?: string | null;
|
||||||
'state'?: string | null;
|
'state'?: string | null;
|
||||||
'title'?: string | null;
|
'title'?: string | null;
|
||||||
|
'videoPrompt'?: string | null;
|
||||||
}
|
}
|
||||||
export interface o_tasks {
|
export interface o_tasks {
|
||||||
'describe'?: string | null;
|
'describe'?: string | null;
|
||||||
@ -232,6 +279,9 @@ export interface o_videoConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DB {
|
export interface DB {
|
||||||
|
"_o_project_old_20260330": _o_project_old_20260330;
|
||||||
|
"_o_storyboard_old_20260325": _o_storyboard_old_20260325;
|
||||||
|
"_o_storyboard_old_20260330": _o_storyboard_old_20260330;
|
||||||
"memories": memories;
|
"memories": memories;
|
||||||
"o_agentDeploy": o_agentDeploy;
|
"o_agentDeploy": o_agentDeploy;
|
||||||
"o_agentWorkData": o_agentWorkData;
|
"o_agentWorkData": o_agentWorkData;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user