Spaces:
Sleeping
Sleeping
Update bullets/generator.py
Browse files- bullets/generator.py +66 -0
bullets/generator.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
def create_bullet_instruction():
|
| 2 |
"""
|
| 3 |
Creates the instruction for generating benefit bullets.
|
|
@@ -186,4 +188,68 @@ def create_bullet_instruction():
|
|
| 186 |
# Combine base instruction with formula instructions
|
| 187 |
complete_instruction = base_instruction + formula_instructions
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
return complete_instruction
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
|
| 3 |
def create_bullet_instruction():
|
| 4 |
"""
|
| 5 |
Creates the instruction for generating benefit bullets.
|
|
|
|
| 188 |
# Combine base instruction with formula instructions
|
| 189 |
complete_instruction = base_instruction + formula_instructions
|
| 190 |
|
| 191 |
+
return complete_instruction
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def get_random_bullet_formula():
|
| 195 |
+
"""
|
| 196 |
+
Randomly selects a bullet formula type to ensure variety in generated bullets.
|
| 197 |
+
Extracts formula names automatically from the instruction text.
|
| 198 |
+
|
| 199 |
+
Returns:
|
| 200 |
+
str: The name of the randomly selected formula
|
| 201 |
+
"""
|
| 202 |
+
# Get the full instruction text
|
| 203 |
+
full_instruction = create_bullet_instruction()
|
| 204 |
+
|
| 205 |
+
# Extract formula names using regex pattern matching
|
| 206 |
+
import re
|
| 207 |
+
|
| 208 |
+
# Pattern to find formula names (looks for "FORMULA X - NAME:")
|
| 209 |
+
formula_pattern = r"FORMULA\s+\d+\s+-\s+([^:]+):"
|
| 210 |
+
|
| 211 |
+
# Find all matches in the instruction text
|
| 212 |
+
formula_matches = re.findall(formula_pattern, full_instruction)
|
| 213 |
+
|
| 214 |
+
# If no formulas found, fallback to manual list
|
| 215 |
+
if not formula_matches:
|
| 216 |
+
formulas = [
|
| 217 |
+
"STANDARD BENEFIT",
|
| 218 |
+
"3 EN 1 (FEATURE + BENEFIT + MEANING)",
|
| 219 |
+
"ANTI-PROCRASTINACIÓN (ACTION + RESULT + TIME)",
|
| 220 |
+
"NÚMERICA SUPREMA"
|
| 221 |
+
]
|
| 222 |
+
else:
|
| 223 |
+
formulas = formula_matches
|
| 224 |
+
|
| 225 |
+
# Select a random formula
|
| 226 |
+
selected_formula = random.choice(formulas)
|
| 227 |
+
|
| 228 |
+
return selected_formula
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def create_bullet_instruction_with_formula():
|
| 232 |
+
"""
|
| 233 |
+
Creates the instruction for generating benefit bullets with a specific
|
| 234 |
+
randomly selected formula to ensure consistency.
|
| 235 |
+
|
| 236 |
+
Returns:
|
| 237 |
+
str: The complete instruction for generating bullets with the selected formula
|
| 238 |
+
"""
|
| 239 |
+
# Get base instruction
|
| 240 |
+
base_instruction = create_bullet_instruction()
|
| 241 |
+
|
| 242 |
+
# Get a random formula
|
| 243 |
+
selected_formula = get_random_bullet_formula()
|
| 244 |
+
|
| 245 |
+
# Add specific instruction to use the selected formula
|
| 246 |
+
formula_directive = f"""
|
| 247 |
+
|
| 248 |
+
IMPORTANT OVERRIDE: For this specific task, you MUST use FORMULA {selected_formula}
|
| 249 |
+
for ALL 5 bullets. Do not choose randomly - you must use this exact formula consistently.
|
| 250 |
+
"""
|
| 251 |
+
|
| 252 |
+
# Combine instructions
|
| 253 |
+
complete_instruction = base_instruction + formula_directive
|
| 254 |
+
|
| 255 |
return complete_instruction
|