11
This commit is contained in:
@@ -8,6 +8,8 @@ import {
|
||||
|
||||
ensureAppConfigReady,
|
||||
|
||||
ensureLlmConfigReady,
|
||||
|
||||
validateShareText,
|
||||
|
||||
DEFAULT_REWRITE_CONFIG,
|
||||
@@ -17,6 +19,7 @@ import {
|
||||
|
||||
|
||||
const PIPELINE_SCRIPT = "douyin_pipeline.js";
|
||||
const SCRIPT_GENERATE = "script_generate.js";
|
||||
const NODEJS_EVENT = "nodejs:event";
|
||||
|
||||
|
||||
@@ -61,6 +64,8 @@ export const useWorkflowStore = defineStore("workflow", {
|
||||
|
||||
videoRewriting: false,
|
||||
|
||||
scriptGenerating: false,
|
||||
|
||||
/** 流水线进度文案(来自 quickjs:event progress) */
|
||||
|
||||
rewriteProgress: "",
|
||||
@@ -315,7 +320,11 @@ export const useWorkflowStore = defineStore("workflow", {
|
||||
|
||||
},
|
||||
|
||||
async generateScript() {
|
||||
|
||||
return executeGenerateScript(this);
|
||||
|
||||
},
|
||||
|
||||
resetAll() {
|
||||
|
||||
@@ -431,7 +440,91 @@ export async function executeVideoRewrite(store) {
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_SCRIPT_PROMPT = `请基于以下视频原文案,创作一个新的仿写文案:
|
||||
|
||||
原文案:{{content}}
|
||||
|
||||
要求:
|
||||
1. 保持原文案的核心内容和风格
|
||||
2. 适当改变表达方式和用词
|
||||
3. 确保新文案通顺自然
|
||||
4. 长度约{{count}}字
|
||||
|
||||
请直接输出仿写后的文案:`;
|
||||
|
||||
/**
|
||||
* 构建撰写文案提示词(对齐 zhenqianba generateScriptFromVideoContent)
|
||||
* @param {ReturnType<typeof useWorkflowStore>} store
|
||||
*/
|
||||
export function buildScriptGeneratePrompt(store) {
|
||||
const content = String(store.recognizedContent || "").trim();
|
||||
const count = store.editWordCount || 300;
|
||||
let prompt = String(store.rewritePrompt || "").trim();
|
||||
if (!prompt) {
|
||||
prompt = DEFAULT_SCRIPT_PROMPT;
|
||||
}
|
||||
prompt = prompt
|
||||
.replace(/\{\{content\}\}/g, content)
|
||||
.replace(/\{content\}/g, content)
|
||||
.replace(/\{\{count\}\}/g, String(count))
|
||||
.replace(/\{count\}/g, String(count));
|
||||
|
||||
const lang = store.editLanguage || "";
|
||||
if (lang && lang !== "中文(普通话)") {
|
||||
prompt = `请用${lang}输出文案。\n\n${prompt}`;
|
||||
}
|
||||
return prompt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 撰写文案:基于识别的原始内容调用 LLM(对齐 Electron ki)
|
||||
* @param {ReturnType<typeof useWorkflowStore>} store
|
||||
*/
|
||||
export async function executeGenerateScript(store) {
|
||||
const content = String(store.recognizedContent || "").trim();
|
||||
if (!content) {
|
||||
return { ok: false, message: "请先使用智能视频仿写功能识别视频内容" };
|
||||
}
|
||||
|
||||
const cfgReady = await ensureLlmConfigReady();
|
||||
if (!cfgReady.ok) {
|
||||
return { ok: false, message: cfgReady.message };
|
||||
}
|
||||
|
||||
const userPrompt = buildScriptGeneratePrompt(store);
|
||||
store.scriptGenerating = true;
|
||||
|
||||
try {
|
||||
const result = await invoke("run_nodejs_script", {
|
||||
scriptName: SCRIPT_GENERATE,
|
||||
params: {
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content:
|
||||
"你是专业的短视频文案改写助手。请把用户提供的文案改写,保持原文的风格和主题,但使用不同的表达方式。",
|
||||
},
|
||||
{ role: "user", content: userPrompt },
|
||||
],
|
||||
temperature: 0.8,
|
||||
max_tokens: 2000,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result?.success || !result?.content) {
|
||||
const err = result?.error || "文案仿写失败,请重试";
|
||||
return { ok: false, message: String(err) };
|
||||
}
|
||||
|
||||
store.scriptContent = String(result.content).trim();
|
||||
return { ok: true, message: "文案仿写完成" };
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err || "未知错误");
|
||||
return { ok: false, message: `文案仿写失败: ${msg}` };
|
||||
} finally {
|
||||
store.scriptGenerating = false;
|
||||
}
|
||||
}
|
||||
|
||||
const UNSUPPORTED_PLATFORM_RULES = [
|
||||
|
||||
|
||||
Reference in New Issue
Block a user