File size: 14,843 Bytes
0943fed
520c50f
9e3f682
0943fed
58ff37d
0943fed
bf165e3
 
1bd2548
af55e5a
 
 
bf165e3
 
af55e5a
 
1bd2548
af55e5a
1bd2548
 
af55e5a
 
 
 
 
bf165e3
 
27908d2
bf165e3
e74b643
26ce1d0
 
 
81df141
e74b643
 
 
520c50f
e74b643
 
 
bf165e3
 
 
 
9e3f682
4362780
0625c7b
9e3f682
 
 
 
 
 
0943fed
bf165e3
 
 
 
 
 
 
81df141
bf165e3
 
b53d55e
bf165e3
9e3f682
 
 
26ce1d0
 
 
c3badaa
bf165e3
 
 
61c1e67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95e1ab0
 
 
61c1e67
 
95e1ab0
 
61c1e67
 
 
 
40b0916
bf165e3
 
520c50f
af55e5a
369b989
 
 
af55e5a
369b989
af55e5a
369b989
 
3ba0740
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af55e5a
 
3ba0740
 
 
af55e5a
 
3ba0740
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af55e5a
 
3ba0740
 
 
af55e5a
 
3ba0740
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af55e5a
 
3ba0740
 
af55e5a
 
 
e74b643
05c5c1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf36c5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05c5c1e
 
bf36c5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05c5c1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
from formulas import offer_formulas
from sophistication.generator import create_sophistication_instruction
from avatar_analysis import analyze_avatar

# Modify the offer_system_prompt to specify the correct format for PUV
offer_system_prompt = """You are a world-class expert copywriter, experienced in creating compelling offers that connect emotionally with the target audience.

OBJECTIVE:
- Generate 3 COMPLETELY DIFFERENT versions of a convincing offer in Spanish
- Each version must be CLEAR, CONCISE and FOCUSED on a SINGLE transformation
- Connect emotionally with the audience's core desire
- Use natural and conversational language

CRITICAL OUTPUT RULES:
- Create 3 DISTINCT versions with different angles and emotional appeals
- Each version must focus on ONE problem/vision, ONE transformation, and ONE proof element
- Number each version clearly as "VERSIÓN 1:", "VERSIÓN 2:", and "VERSIÓN 3:"
- Output ONLY the offers themselves with NO explanations or commentary
- Start each version directly with its corresponding formula structure
- Present all 3 versions one after another, clearly separated

FORMULA-SPECIFIC FOCUS:
1. Oferta Dorada: ONE specific problem, ONE clear transformation, ONE proof element
2. Contraste Revelador: ONE inspiring vision, ONE transformative solution, ONE emotional result
3. Propuesta Única de Valor: ONE powerful transformation, ONE emotional objection handler
"""

def create_offer_instruction(target_audience=None, product_service=None, selected_formula_name=None, file_content=None, skills=None, sophistication_level=None):
    """
    Creates the instruction for generating an offer based on the selected formula.
    
    Args:
        target_audience: Description of the target audience
        product_service: Product/service information
        selected_formula_name: Name of the selected formula
        file_content: Content from uploaded files (if any)
        skills: User's skills and expertise
        sophistication_level: String key for the market sophistication level
    
    Returns:
        str: The complete instruction for generating the offer
    """
    # Get the selected formula
    selected_formula = offer_formulas[selected_formula_name]
    
    # Get formula-specific instructions
    additional_instructions = selected_formula.get("instructions", "")
    
    # Process avatar analysis if target_audience is provided
    avatar_insights = ""
    if target_audience:
        avatar_insights = analyze_avatar(target_audience)  # This would call your avatar analysis function
    
    # Create the base instruction with avatar insights
    instruction = f"""{offer_system_prompt}

FORMULA TO USE:
{selected_formula["description"]}

{additional_instructions}

PRODUCT/SERVICE:
{product_service}

TARGET AUDIENCE:
{target_audience}

AVATAR ANALYSIS:
{avatar_insights}

ADDITIONAL INFORMATION:
{file_content}

Create a compelling offer following the formula structure exactly, adapting it to the sophistication level provided.
"""
    
    # Add examples if available
    if selected_formula.get("sophistication_examples") and sophistication_level:
        # Extract the sophistication level key (e.g., "nivel_1", "nivel_2", etc.)
        sophistication_key = sophistication_level.split(":")[0].lower().replace(" ", "_")
        
        # Map to the correct key format used in the examples
        if "nivel" not in sophistication_key:
            sophistication_key = f"nivel_{sophistication_key[0]}"
        
        # Get all examples for the specific sophistication level
        examples = []
        for key, example in selected_formula["sophistication_examples"].items():
            # Check if the key starts with the sophistication level (to include nivel_1, nivel_1_ejemplo2, etc.)
            if key.startswith(sophistication_key):
                examples.append(example)
        
        # Format all examples based on the formula type
        if examples:
            instruction += "\n\n### EXAMPLES FOR YOUR REFERENCE:\n"
            
            for i, example in enumerate(examples):
                instruction += f"\n#### Example {i+1}:\n"
                
                # Format based on formula type
                if selected_formula_name == "Oferta Dorada":
                    instruction += f"Headline: {example.get('headline', '')}\n"
                    instruction += f"Promise: {example.get('promise', '')}\n"
                    instruction += f"Subtitle: {example.get('subtitle', '')}\n"
                
                elif selected_formula_name == "Contraste Revelador":
                    instruction += f"Situación: {example.get('situation', '')}\n"
                    instruction += f"Solución: {example.get('solution', '')}\n"
                    instruction += f"Resultado: {example.get('result', '')}\n"
                
                elif selected_formula_name == "Propuesta Única de Valor":
                    instruction += f"Transformación: {example.get('transformation', '')}\n"
                    instruction += f"Objeciones: {example.get('objections', '')}\n"
                
                # Add more formula types as needed
    # Original code for general examples (keep as fallback)
    elif selected_formula.get("examples") and len(selected_formula["examples"]) > 0:
        examples_text = "\n\n".join([f"Example {i+1}:\n{example}" for i, example in enumerate(selected_formula["examples"])])
        instruction += f"\n\nGet inspired by these examples:\n{examples_text}"
    
    # Add sophistication level guidance using the dedicated function
    if sophistication_level:
        # Get basic sophistication guidance
        base_sophistication_guidance = create_sophistication_instruction(sophistication_level)
        
        # Create concise formula-specific guidance based on sophistication level
        formula_specific_guidance = ""
        level_num = sophistication_level.split(":")[0].replace("Nivel ", "")
        
        if selected_formula_name == "Oferta Dorada":
            # Guidance dictionaries for Oferta Dorada
            headline_guidance = {
                "1": "Educational, introduce the concept as new",
                "2": "Differentiate from competitors, add specific benefits",
                "3": "Highlight unique mechanism or approach",
                "4": "Use data, research or challenge beliefs",
                "5": "Focus on identity and emotional transformation"
            }
            
            promise_guidance = {
                "1": "Direct and clear benefit without comparisons",
                "2": "Quantified benefit with specific advantage",
                "3": "Unique mechanism or proprietary method",
                "4": "Evidence-backed transformation with specifics",
                "5": "Identity shift and deeper meaning beyond results"
            }
            
            subtitle_guidance = {
                "1": "Simple proof with basic numbers",
                "2": "Comparative results with timeframes",
                "3": "Specific mechanism results with details",
                "4": "Research-backed evidence and guarantees",
                "5": "Community and movement-based validation"
            }
            
            formula_specific_guidance = f"""
For Oferta Dorada (Nivel {level_num}):
- Headline: {headline_guidance.get(level_num, "Match market awareness level")}
- Promise: {promise_guidance.get(level_num, "Focus on transformation")}
- Subtitle: {subtitle_guidance.get(level_num, "Provide appropriate proof")}"""
        
        elif selected_formula_name == "Contraste Revelador":
            # Guidance dictionaries for Contraste Revelador
            vision_guidance = {
                "1": "Simple, aspirational future state",
                "2": "Specific vision with clear advantages",
                "3": "Unique approach to achieving desires",
                "4": "Evidence-based optimal state",
                "5": "Transcendent vision beyond conventional goals"
            }
            
            solution_guidance = {
                "1": "Clear, straightforward solution",
                "2": "Solution with specific advantages",
                "3": "Unique mechanism or proprietary method",
                "4": "Validated solution with research backing",
                "5": "Paradigm-shifting approach"
            }
            
            result_guidance = {
                "1": "Simple emotional outcome with basic proof",
                "2": "Specific results with comparative advantages",
                "3": "Detailed outcomes from unique approach",
                "4": "Evidence-backed results with specifics",
                "5": "Identity-level transformation stories"
            }
            
            formula_specific_guidance = f"""
For Contraste Revelador (Nivel {level_num}):
- Visión: {vision_guidance.get(level_num, "Create inspiring vision")}
- Solución: {solution_guidance.get(level_num, "Offer transformative solution")}
- Resultado: {result_guidance.get(level_num, "Show emotional transformation")}"""
        
        elif selected_formula_name == "Propuesta Única de Valor":
            # Guidance dictionaries for Propuesta Única de Valor
            transformation_guidance = {
                "1": "Clear, direct transformation",
                "2": "Specific, quantified transformation",
                "3": "Unique mechanism transformation",
                "4": "Evidence-backed, validated transformation",
                "5": "Identity-level, paradigm-shifting transformation"
            }
            
            objection_guidance = {
                "1": "Address basic concerns simply",
                "2": "Counter specific objections with advantages",
                "3": "Handle objections with unique approach",
                "4": "Evidence-based objection handling",
                "5": "Transform objections into strengths"
            }
            
            formula_specific_guidance = f"""
For Propuesta Única de Valor (Nivel {level_num}):
- Transformación: {transformation_guidance.get(level_num, "Focus on key transformation")}
- Objeciones: {objection_guidance.get(level_num, "Handle emotional objections")}"""
        
        # Add the concise guidance to the instruction
        instruction += f"\n\nSOPHISTICATION GUIDANCE (NIVEL {level_num}):{formula_specific_guidance}"
    
    return instruction


def create_integrated_instruction(target_audience=None, product_service=None, selected_formula_name=None, 
                                 file_content=None, bullet_content=None, bonus_content=None, skills=None, 
                                 sophistication_level=None):
    """
    Crea una instrucción integrada que combina la oferta principal, los beneficios y los bonos
    con un formato consistente para todas las fórmulas.
    
    Args:
        target_audience: Descripción del público objetivo
        product_service: Información del producto/servicio
        selected_formula_name: Nombre de la fórmula seleccionada
        file_content: Contenido de archivos subidos para la oferta principal
        bullet_content: Contenido de archivos subidos para los beneficios
        bonus_content: Contenido de archivos subidos para los bonos
        skills: Habilidades y experiencia del usuario
        sophistication_level: Nivel de sofisticación del mercado
        
    Returns:
        str: Instrucción completa e integrada
    """
    from bullets.generator import create_bullet_instruction
    from bonuses.generator import create_bonus_instruction
    
    # Crear la instrucción base para la oferta principal
    offer_instruction = create_offer_instruction(
        target_audience=target_audience,
        product_service=product_service,
        selected_formula_name=selected_formula_name,
        file_content=file_content,
        skills=skills,
        sophistication_level=sophistication_level
    )
    
    # Crear instrucciones para los beneficios
    try:
        bullet_instruction = create_bullet_instruction(
            target_audience=target_audience,
            product_service=product_service,
            selected_formula_name=selected_formula_name,
            uploaded_content=bullet_content or file_content,  # Priorizar bullet_content si existe
            skills=skills
        )
    except TypeError:
        # Si la función no acepta selected_formula_name, llamarla sin ese parámetro
        bullet_instruction = create_bullet_instruction(
            target_audience=target_audience,
            product_service=product_service,
            uploaded_content=bullet_content or file_content,  # Priorizar bullet_content si existe
            skills=skills
        )
    
    # Crear instrucciones para los bonos
    try:
        bonus_instruction = create_bonus_instruction(
            target_audience=target_audience,
            product_service=product_service,
            selected_formula_name=selected_formula_name,
            uploaded_content=bonus_content or file_content,  # Priorizar bonus_content si existe
            skills=skills
        )
    except TypeError:
        # Si la función no acepta selected_formula_name, llamarla sin ese parámetro
        bonus_instruction = create_bonus_instruction(
            target_audience=target_audience,
            product_service=product_service,
            uploaded_content=bonus_content or file_content,  # Priorizar bonus_content si existe
            skills=skills
        )
    
    # Instrucción de integración que especifica el formato exacto para todas las fórmulas
    integration_instruction = f"""
INSTRUCCIÓN DE INTEGRACIÓN IMPORTANTE:

Para cada una de las 3 versiones de oferta que generes, sigue EXACTAMENTE esta estructura:

VERSIÓN X:
[Promesa principal según la fórmula {selected_formula_name}]

BENEFICIOS:
• [Beneficio específico 1]
• [Beneficio específico 2]
• [Beneficio específico 3]
• [Beneficio específico 4]
• [Beneficio específico 5]

BONOS:
• BONO #1: [NOMBRE ATRACTIVO] - [Descripción breve] - Valor: $X
• BONO #2: [NOMBRE ATRACTIVO] - [Descripción breve] - Valor: $X
• BONO #3: [NOMBRE ATRACTIVO] - [Descripción breve] - Valor: $X

Valor total de bonos: $XXX - Todo incluido con tu inversión hoy.

IMPORTANTE: 
- Mantén esta estructura exacta para TODAS las fórmulas, incluyendo Propuesta Única de Valor
- Cada versión debe tener su propia sección de BENEFICIOS y BONOS
- Presenta las 3 versiones completas una tras otra
- No incluyas explicaciones o comentarios adicionales
"""
    
    # Combinar todas las instrucciones
    complete_instruction = offer_instruction + "\n\n" + bullet_instruction + "\n\n" + bonus_instruction + "\n\n" + integration_instruction
    
    return complete_instruction