title_generation.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Title generation prompt
  14. For generating video title from content.
  15. """
  16. TITLE_GENERATION_PROMPT = """Please generate a short, attractive title for the following content.
  17. Content:
  18. {content}
  19. Requirements:
  20. 1. **Language Consistency (CRITICAL)**: The title MUST be in the same language as the input content
  21. - If the input content is in English, the title MUST be in English
  22. - If the input content is in Chinese, the title MUST be in Chinese
  23. - Strictly follow the language of the input content
  24. 2. **Character Limit (CRITICAL)**: The title MUST NOT exceed {max_length} characters
  25. - Count every character including spaces
  26. - The title must be complete and meaningful within this limit
  27. - Do NOT generate a title that would need to be cut off
  28. 3. **Core Message (CRITICAL)**: The title MUST capture the MAIN POINT of the content
  29. - Identify the central theme or key message
  30. - Don't focus on just one aspect if the content has multiple important points
  31. - Ensure the title accurately represents what the content is about
  32. 4. **No Punctuation at End**: Do NOT include any punctuation marks at the end of the title
  33. - No period (.), comma (,), exclamation mark (!), question mark (?), etc.
  34. - The title should end with a word or number, not punctuation
  35. 5. **Completeness**: Ensure the title is a complete, meaningful phrase
  36. - Do not cut off in the middle of a word or number
  37. - Do not create incomplete phrases like "Rise Early for" or "How to Make"
  38. - Use abbreviations or shorter words if needed to fit the limit
  39. 6. **Abbreviation Examples** (use when needed to fit character limit):
  40. - For English:
  41. * "10,000" → "10K"
  42. * "per month" → "monthly" or "a month"
  43. * "early to bed and early to rise" → "Sleep Early" or "Early Habits"
  44. * "makes you healthy" → "for Health" or "Stay Healthy"
  45. - For Chinese:
  46. * "10,000元" → "万元" or "1万"
  47. * "每个月" → "月入" or "月收"
  48. 7. Accurately summarize the core content
  49. 8. Attractive and engaging, suitable as a video title
  50. 9. Output only the title text, no quotes, no explanations
  51. Title:"""
  52. def build_title_generation_prompt(content: str, max_length: int = 15) -> str:
  53. """
  54. Build title generation prompt
  55. Args:
  56. content: Content to generate title from
  57. max_length: Maximum title length in characters (default: 15)
  58. Returns:
  59. Formatted prompt with character limit
  60. """
  61. # Take first 500 chars to avoid overly long prompts
  62. content_preview = content[:500]
  63. return TITLE_GENERATION_PROMPT.format(
  64. content=content_preview,
  65. max_length=max_length
  66. )