返回 Pixelle-Video
prompt_helper.py
根目录 / pixelle_video / utils / prompt_helper.py
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 Prompt helper utilities
15
16 Simple utilities for building prompts with optional prefixes.
17 """
18
19
20 def build_image_prompt(prompt: str, prefix: str = "") -> str:
21 """
22 Build final image prompt with optional prefix
23
24 Args:
25 prompt: User's raw prompt
26 prefix: Optional prefix to add before the prompt
27
28 Returns:
29 Final prompt with prefix applied (if provided)
30
31 Examples:
32 >>> build_image_prompt("a cat", "")
33 'a cat'
34
35 >>> build_image_prompt("a cat", "anime style")
36 'anime style, a cat'
37
38 >>> build_image_prompt("a cat", " anime style ")
39 'anime style, a cat'
40 """
41 prefix = prefix.strip() if prefix else ""
42 prompt = prompt.strip() if prompt else ""
43
44 if prefix and prompt:
45 return f"{prefix}, {prompt}"
46 elif prefix:
47 return prefix
48 else:
49 return prompt
50
51
51 lines PYTHON