JeCabrera commited on
Commit
31a5a91
verified
1 Parent(s): 1570b1f

Update formulas.py

Browse files
Files changed (1) hide show
  1. formulas.py +79 -15
formulas.py CHANGED
@@ -13,6 +13,62 @@ CRITICAL OUTPUT RULES:
13
  - Do not include phrases like "Aqu铆 tienes una oferta convincente" or "Esta es tu oferta"
14
  """
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def create_offer_instruction(avatar_description, product_name, selected_formula_name):
17
  """
18
  Creates instructions for generating an offer based on the selected formula.
@@ -25,6 +81,9 @@ def create_offer_instruction(avatar_description, product_name, selected_formula_
25
  Returns:
26
  str: Complete instruction for generating the offer
27
  """
 
 
 
28
  # Get the selected formula
29
  selected_formula = offer_formulas[selected_formula_name]
30
 
@@ -34,16 +93,14 @@ def create_offer_instruction(avatar_description, product_name, selected_formula_
34
  additional_instructions = """
35
  SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
36
  1. PRODUCT/SERVICE NAME HANDLING:
37
- - If product_name is provided and not empty, use it EXACTLY as written
38
- - If product_name is empty, generic (like "Producto/Servicio"), or contains placeholders, CREATE a compelling name that:
39
- * Reflects the target audience's desires and challenges
40
- * Communicates the main benefit or transformation
41
- * Sounds professional and memorable
42
- * Is specific to the niche or industry mentioned in avatar_description
43
- - If product_name contains a full phrase like "Un curso llamado Ingl茅s sin problemas", extract only the real name ("Ingl茅s sin problemas")
44
 
45
  2. Analyze ALL available information:
46
- - Product/service name (product_name variable) or create one if needed
47
  - Target audience description (avatar_description)
48
  - Content from uploaded files (if any)
49
 
@@ -54,7 +111,7 @@ SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
54
 
55
  4. Create a comprehensive offer by combining:
56
  - The appropriate type (determined in step 3)
57
- - The exact product name (if provided) or your created name (if needed)
58
  - A compelling dream based on avatar_description
59
  - A relevant obstacle based on avatar_description
60
 
@@ -77,23 +134,30 @@ SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
77
  - "Ahora puedes acceder a un..."
78
  - "Tenemos para ti un..."
79
  - "Disfruta de un..."
80
- """
81
 
82
  elif selected_formula_name == "Oferta Dorada":
83
  additional_instructions = """
84
  SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
85
- 1. ATTENTION HOOK HANDLING:
 
 
 
 
 
 
 
86
  - Analyze the avatar_description DEEPLY to understand their specific pain points, frustrations, and desires
87
  - Select a powerful attention hook that DIRECTLY connects with the avatar's current reality
88
  - DO NOT use questions as hooks - use statements, statistics, or shocking revelations instead
89
  - CUSTOMIZE the hook specifically for this avatar - don't use generic examples
90
  - The hook MUST address the SAME problem that your promise will solve
91
 
92
- 2. MAINTAIN THEMATIC CONSISTENCY:
93
  - The attention hook, quantifiable promise, and benefit statement MUST all address the SAME problem
94
  - Create a LOGICAL PROGRESSION from problem (hook) to solution (promise) to implementation (benefit)
95
 
96
- 3. Create a compelling QUANTIFIABLE PROMISE that:
97
  - Is written COMPLETELY IN CAPITAL LETTERS
98
  - Includes concrete numbers (money, time, results)
99
  - Uses powerful action verbs (EARN, MULTIPLY, ACHIEVE, MASTER)
@@ -102,12 +166,12 @@ SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
102
  - NEVER uses exclamation marks (!)
103
  - DIRECTLY addresses the same problem mentioned in the hook
104
 
105
- 4. Craft a benefit statement that:
106
  - Clearly explains the result they will obtain
107
  - Includes an authority element (proven method, studies, experience)
108
  - Establishes a realistic timeframe or effort needed
109
  - CONTINUES the same theme established in the hook and promise
110
- """
111
 
112
  # Create the instruction using the system prompt at the beginning
113
  instruction = f"""{offer_system_prompt}
 
13
  - Do not include phrases like "Aqu铆 tienes una oferta convincente" or "Esta es tu oferta"
14
  """
15
 
16
+ def extract_product_name(product_name_input):
17
+ """
18
+ Extracts the actual product name from user input, especially when it's enclosed in quotes.
19
+
20
+ Args:
21
+ product_name_input: The raw input string containing the product name
22
+
23
+ Returns:
24
+ str: The extracted product name, or empty string if generic
25
+ """
26
+ import re
27
+
28
+ # If input is empty or None, return empty string
29
+ if not product_name_input or product_name_input.strip() == "":
30
+ return ""
31
+
32
+ # Check if there's a name in quotes
33
+ quote_pattern = r'"([^"]+)"'
34
+ matches = re.findall(quote_pattern, product_name_input)
35
+
36
+ if matches:
37
+ # Return the first quoted string found
38
+ return matches[0]
39
+
40
+ # If no quotes but contains "llamado" or similar phrases, extract what follows
41
+ called_patterns = [
42
+ r'llamado\s+(.+?)(?:\s+que|\s+con|\s+para|\.$|$)',
43
+ r'titulado\s+(.+?)(?:\s+que|\s+con|\s+para|\.$|$)',
44
+ r'denominado\s+(.+?)(?:\s+que|\s+con|\s+para|\.$|$)',
45
+ r'nombrado\s+(.+?)(?:\s+que|\s+con|\s+para|\.$|$)'
46
+ ]
47
+
48
+ for pattern in called_patterns:
49
+ matches = re.search(pattern, product_name_input, re.IGNORECASE)
50
+ if matches:
51
+ extracted = matches.group(1).strip()
52
+ # If the extracted text has quotes, remove them
53
+ if extracted.startswith('"') and extracted.endswith('"'):
54
+ extracted = extracted[1:-1]
55
+ return extracted
56
+
57
+ # Check if the input is generic (common course/product types without specific names)
58
+ generic_patterns = [
59
+ r'^(curso|taller|programa|webinar|entrenamiento|sistema|m茅todo|servicio|producto|aplicaci贸n|comunidad|masterclass)(\s+de\s+.+)?$',
60
+ r'^(un|el|mi|nuestro)\s+(curso|taller|programa|webinar|entrenamiento|sistema|m茅todo|servicio|producto|aplicaci贸n|comunidad|masterclass)(\s+de\s+.+)?$'
61
+ ]
62
+
63
+ for pattern in generic_patterns:
64
+ if re.match(pattern, product_name_input.lower(), re.IGNORECASE):
65
+ # This is a generic description, return empty string to trigger creative name generation
66
+ return ""
67
+
68
+ # If no patterns match, return the original input
69
+ return product_name_input.strip()
70
+
71
+
72
  def create_offer_instruction(avatar_description, product_name, selected_formula_name):
73
  """
74
  Creates instructions for generating an offer based on the selected formula.
 
81
  Returns:
82
  str: Complete instruction for generating the offer
83
  """
84
+ # Extract the actual product name if it's in quotes or after "llamado"
85
+ extracted_name = extract_product_name(product_name)
86
+
87
  # Get the selected formula
88
  selected_formula = offer_formulas[selected_formula_name]
89
 
 
93
  additional_instructions = """
94
  SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
95
  1. PRODUCT/SERVICE NAME HANDLING:
96
+ - CRITICAL: If a product name is provided in quotes or after words like "llamado", "titulado", etc.,
97
+ YOU MUST USE THAT EXACT NAME. This is non-negotiable.
98
+ - The extracted product name is: "{extracted_name}"
99
+ - If this extracted name is not empty, use it EXACTLY as provided with no modifications
100
+ - Only create a new name if the extracted name is empty or contains generic placeholders
 
 
101
 
102
  2. Analyze ALL available information:
103
+ - Product/service name (use the extracted name provided above)
104
  - Target audience description (avatar_description)
105
  - Content from uploaded files (if any)
106
 
 
111
 
112
  4. Create a comprehensive offer by combining:
113
  - The appropriate type (determined in step 3)
114
+ - The EXACT product name as extracted (if provided)
115
  - A compelling dream based on avatar_description
116
  - A relevant obstacle based on avatar_description
117
 
 
134
  - "Ahora puedes acceder a un..."
135
  - "Tenemos para ti un..."
136
  - "Disfruta de un..."
137
+ """.format(extracted_name=extracted_name)
138
 
139
  elif selected_formula_name == "Oferta Dorada":
140
  additional_instructions = """
141
  SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
142
+ 1. PRODUCT/SERVICE NAME HANDLING:
143
+ - CRITICAL: If a product name is provided in quotes or after words like "llamado", "titulado", etc.,
144
+ YOU MUST USE THAT EXACT NAME. This is non-negotiable.
145
+ - The extracted product name is: "{extracted_name}"
146
+ - If this extracted name is not empty, use it EXACTLY as provided with no modifications
147
+ - Only create a new name if the extracted name is empty or contains generic placeholders
148
+
149
+ 2. ATTENTION HOOK HANDLING:
150
  - Analyze the avatar_description DEEPLY to understand their specific pain points, frustrations, and desires
151
  - Select a powerful attention hook that DIRECTLY connects with the avatar's current reality
152
  - DO NOT use questions as hooks - use statements, statistics, or shocking revelations instead
153
  - CUSTOMIZE the hook specifically for this avatar - don't use generic examples
154
  - The hook MUST address the SAME problem that your promise will solve
155
 
156
+ 3. MAINTAIN THEMATIC CONSISTENCY:
157
  - The attention hook, quantifiable promise, and benefit statement MUST all address the SAME problem
158
  - Create a LOGICAL PROGRESSION from problem (hook) to solution (promise) to implementation (benefit)
159
 
160
+ 4. Create a compelling QUANTIFIABLE PROMISE that:
161
  - Is written COMPLETELY IN CAPITAL LETTERS
162
  - Includes concrete numbers (money, time, results)
163
  - Uses powerful action verbs (EARN, MULTIPLY, ACHIEVE, MASTER)
 
166
  - NEVER uses exclamation marks (!)
167
  - DIRECTLY addresses the same problem mentioned in the hook
168
 
169
+ 5. Craft a benefit statement that:
170
  - Clearly explains the result they will obtain
171
  - Includes an authority element (proven method, studies, experience)
172
  - Establishes a realistic timeframe or effort needed
173
  - CONTINUES the same theme established in the hook and promise
174
+ """.format(extracted_name=extracted_name)
175
 
176
  # Create the instruction using the system prompt at the beginning
177
  instruction = f"""{offer_system_prompt}