| 1 | # Copyright (C) 2025 AIDC-AI |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | # See the License for the specific language governing permissions and |
| 11 | # limitations under the License. |
| 12 | |
| 13 | """ |
| 14 | Title generation prompt |
| 15 | |
| 16 | For generating video title from content. |
| 17 | """ |
| 18 | |
| 19 | |
| 20 | TITLE_GENERATION_PROMPT = """Please generate a short, attractive title for the following content. |
| 21 | |
| 22 | Content: |
| 23 | {content} |
| 24 | |
| 25 | Requirements: |
| 26 | 1. **Language Consistency (CRITICAL)**: The title MUST be in the same language as the input content |
| 27 | - If the input content is in English, the title MUST be in English |
| 28 | - If the input content is in Chinese, the title MUST be in Chinese |
| 29 | - Strictly follow the language of the input content |
| 30 | |
| 31 | 2. **Character Limit (CRITICAL)**: The title MUST NOT exceed {max_length} characters |
| 32 | - Count every character including spaces |
| 33 | - The title must be complete and meaningful within this limit |
| 34 | - Do NOT generate a title that would need to be cut off |
| 35 | |
| 36 | 3. **Core Message (CRITICAL)**: The title MUST capture the MAIN POINT of the content |
| 37 | - Identify the central theme or key message |
| 38 | - Don't focus on just one aspect if the content has multiple important points |
| 39 | - Ensure the title accurately represents what the content is about |
| 40 | |
| 41 | 4. **No Punctuation at End**: Do NOT include any punctuation marks at the end of the title |
| 42 | - No period (.), comma (,), exclamation mark (!), question mark (?), etc. |
| 43 | - The title should end with a word or number, not punctuation |
| 44 | |
| 45 | 5. **Completeness**: Ensure the title is a complete, meaningful phrase |
| 46 | - Do not cut off in the middle of a word or number |
| 47 | - Do not create incomplete phrases like "Rise Early for" or "How to Make" |
| 48 | - Use abbreviations or shorter words if needed to fit the limit |
| 49 | |
| 50 | 6. **Abbreviation Examples** (use when needed to fit character limit): |
| 51 | - For English: |
| 52 | * "10,000" → "10K" |
| 53 | * "per month" → "monthly" or "a month" |
| 54 | * "early to bed and early to rise" → "Sleep Early" or "Early Habits" |
| 55 | * "makes you healthy" → "for Health" or "Stay Healthy" |
| 56 | - For Chinese: |
| 57 | * "10,000元" → "万元" or "1万" |
| 58 | * "每个月" → "月入" or "月收" |
| 59 | |
| 60 | 7. Accurately summarize the core content |
| 61 | 8. Attractive and engaging, suitable as a video title |
| 62 | 9. Output only the title text, no quotes, no explanations |
| 63 | |
| 64 | Title:""" |
| 65 | |
| 66 | |
| 67 | def build_title_generation_prompt(content: str, max_length: int = 15) -> str: |
| 68 | """ |
| 69 | Build title generation prompt |
| 70 | |
| 71 | Args: |
| 72 | content: Content to generate title from |
| 73 | max_length: Maximum title length in characters (default: 15) |
| 74 | |
| 75 | Returns: |
| 76 | Formatted prompt with character limit |
| 77 | """ |
| 78 | # Take first 500 chars to avoid overly long prompts |
| 79 | content_preview = content[:500] |
| 80 | |
| 81 | return TITLE_GENERATION_PROMPT.format( |
| 82 | content=content_preview, |
| 83 | max_length=max_length |
| 84 | ) |
| 85 | |
| 86 |