diff --git a/pixelle_video/pipelines/asset_based.py b/pixelle_video/pipelines/asset_based.py index 5c85cac..fd89ab9 100644 --- a/pixelle_video/pipelines/asset_based.py +++ b/pixelle_video/pipelines/asset_based.py @@ -308,6 +308,8 @@ class AssetBasedPipeline(LinearVideoPipeline): Returns: Updated context with generated script (scenes already have asset_path assigned) """ + from pixelle_video.prompts.asset_script_generation import build_asset_script_prompt + logger.info("🤖 Generating video script with LLM...") # Emit progress for script generation (15% - 25%) @@ -328,34 +330,13 @@ class AssetBasedPipeline(LinearVideoPipeline): assets_text = "\n".join(asset_info) - # Build title section for prompt (only if title is provided) - title_section = f"- Video Title: {title}\n" if title else "" - - prompt = f"""You are a video script writer. Generate a {duration}-second video script. - -## Requirements -{title_section}- Intent: {intent} -- Target Duration: {duration} seconds - -## Available Assets (use the exact path in your response) -{assets_text} - -## Instructions -1. Decide how many scenes are needed based on the target duration (typically 5-15 seconds per scene) -2. For each scene, directly assign ONE asset from the available assets above -3. Each scene can have 1-5 narration sentences -4. Try to use all available assets, but it's OK to reuse if needed -5. Total duration of all scenes should be approximately {duration} seconds -{f"6. The narrations should align with the video title: {title}" if title else ""} - -## Output Requirements -For each scene, provide: -- scene_number: Sequential number starting from 1 -- asset_path: The EXACT path from the available assets list -- narrations: Array of 1-5 narration sentences -- duration: Estimated duration in seconds - -Generate the video script now:""" + # Build prompt using the centralized prompt function + prompt = build_asset_script_prompt( + intent=intent, + duration=duration, + assets_text=assets_text, + title=title + ) # Call LLM with structured output script: VideoScript = await self.core.llm( diff --git a/pixelle_video/prompts/asset_script_generation.py b/pixelle_video/prompts/asset_script_generation.py new file mode 100644 index 0000000..0aade20 --- /dev/null +++ b/pixelle_video/prompts/asset_script_generation.py @@ -0,0 +1,80 @@ +# Copyright (C) 2025 AIDC-AI +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Asset-based video script generation prompt + +For generating video scripts based on user-provided assets. +""" + + +ASSET_SCRIPT_GENERATION_PROMPT = """你是一位专业的视频脚本创作者。请基于用户提供的视频意图和可用素材,生成一个 {duration} 秒的视频脚本。 + +## 需求信息 +{title_section}- 视频意图:{intent} +- 目标时长:{duration} 秒 + +## 可用素材(请在输出中使用精确路径) +{assets_text} + +## 创作指南 +1. 根据目标时长决定需要多少个场景(通常每个场景 5-15 秒) +2. 为每个场景从可用素材中直接分配一个素材 +3. 每个场景可以包含 1-3 句旁白 +4. 尽量使用所有可用素材,但如有需要可以复用素材 +5. 所有场景的总时长应约等于 {duration} 秒 +{title_instruction} + +## 语言一致性要求(非常重要) +- 旁白的语言必须与用户输入的视频意图保持一致 +- 如果视频意图是中文,则旁白必须是中文 +- 如果视频意图是英文,则旁白必须是英文 +- 除非视频意图中明确指定了输出语言,否则严格遵循意图的原始语言 + +## 输出要求 +为每个场景提供: +- scene_number: 场景编号(从 1 开始) +- asset_path: 从可用素材列表中选择的精确路径 +- narrations: 包含 1-3 句旁白的数组 +- duration: 预估时长(秒) + +现在请开始生成视频脚本:""" + + +def build_asset_script_prompt( + intent: str, + duration: int, + assets_text: str, + title: str = "" +) -> str: + """ + Build asset-based script generation prompt + + Args: + intent: Video intent/purpose + duration: Target duration in seconds + assets_text: Formatted text of available assets with descriptions + title: Optional video title + + Returns: + Formatted prompt + """ + title_section = f"- 视频标题:{title}\n" if title else "" + title_instruction = f"6. 旁白内容应与视频标题保持一致:{title}\n" if title else "" + + return ASSET_SCRIPT_GENERATION_PROMPT.format( + duration=duration, + title_section=title_section, + intent=intent, + assets_text=assets_text, + title_instruction=title_instruction + )