rodunia commited on
Commit
cf4b843
Β·
1 Parent(s): c2a4d66

fix: update faq.j2 and blog_post_promo.j2 to support enhanced YAML structure

Browse files
Files changed (3) hide show
  1. prompts/blog_post_promo.j2 +48 -0
  2. prompts/faq.j2 +48 -0
  3. test_render_fix.py +15 -12
prompts/blog_post_promo.j2 CHANGED
@@ -31,24 +31,66 @@ PRODUCT NAME: {{ name }}
31
  REGION: {{ region }}
32
 
33
  TECHNICAL SPECIFICATIONS:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  {% for spec in specs %}
35
  - {{ spec }}
36
  {% endfor %}
 
37
 
38
  AUTHORIZED CLAIMS (use ONLY these):
 
 
 
 
 
 
 
 
39
  {% for claim in authorized_claims %}
40
  - {{ claim }}
41
  {% endfor %}
 
42
 
43
  PROHIBITED CLAIMS (never use these):
 
 
 
 
 
 
 
 
44
  {% for claim in prohibited_or_unsupported_claims %}
45
  - {{ claim }}
46
  {% endfor %}
 
47
 
48
  MANDATORY DISCLAIMERS (include verbatim at end):
 
 
 
 
 
49
  {% for disclaimer in disclaimers %}
50
  - {{ disclaimer }}
51
  {% endfor %}
 
52
 
53
  ═════════════════════════════════════════════════════════
54
  TARGET AUDIENCE PSYCHOLOGY
@@ -190,6 +232,12 @@ OUTPUT FORMAT (STRICT)
190
  ---
191
 
192
  **Disclaimers:**
 
 
 
 
 
193
  {% for disclaimer in disclaimers %}
194
  {{ disclaimer }}
195
  {% endfor %}
 
 
31
  REGION: {{ region }}
32
 
33
  TECHNICAL SPECIFICATIONS:
34
+ {% if specs is mapping %}
35
+ {% for category, items in specs.items() %}
36
+ {{ category }}:
37
+ {% if items is mapping %}
38
+ {% for subcategory, subitems in items.items() %}
39
+ {{ subcategory }}:
40
+ {% for item in subitems %}
41
+ - {{ item }}
42
+ {% endfor %}
43
+ {% endfor %}
44
+ {% else %}
45
+ {% for item in items %}
46
+ - {{ item }}
47
+ {% endfor %}
48
+ {% endif %}
49
+ {% endfor %}
50
+ {% else %}
51
  {% for spec in specs %}
52
  - {{ spec }}
53
  {% endfor %}
54
+ {% endif %}
55
 
56
  AUTHORIZED CLAIMS (use ONLY these):
57
+ {% if authorized_claims is mapping %}
58
+ {% for category, claims in authorized_claims.items() %}
59
+ {{ category }}:
60
+ {% for claim in claims %}
61
+ - {{ claim }}
62
+ {% endfor %}
63
+ {% endfor %}
64
+ {% else %}
65
  {% for claim in authorized_claims %}
66
  - {{ claim }}
67
  {% endfor %}
68
+ {% endif %}
69
 
70
  PROHIBITED CLAIMS (never use these):
71
+ {% if prohibited_or_unsupported_claims is mapping %}
72
+ {% for category, claims in prohibited_or_unsupported_claims.items() %}
73
+ {{ category }}:
74
+ {% for claim in claims %}
75
+ - {{ claim }}
76
+ {% endfor %}
77
+ {% endfor %}
78
+ {% else %}
79
  {% for claim in prohibited_or_unsupported_claims %}
80
  - {{ claim }}
81
  {% endfor %}
82
+ {% endif %}
83
 
84
  MANDATORY DISCLAIMERS (include verbatim at end):
85
+ {% if mandatory_statements is defined %}
86
+ {% for statement in mandatory_statements %}
87
+ - {{ statement }}
88
+ {% endfor %}
89
+ {% elif disclaimers is defined %}
90
  {% for disclaimer in disclaimers %}
91
  - {{ disclaimer }}
92
  {% endfor %}
93
+ {% endif %}
94
 
95
  ═════════════════════════════════════════════════════════
96
  TARGET AUDIENCE PSYCHOLOGY
 
232
  ---
233
 
234
  **Disclaimers:**
235
+ {% if mandatory_statements is defined %}
236
+ {% for statement in mandatory_statements %}
237
+ {{ statement }}
238
+ {% endfor %}
239
+ {% elif disclaimers is defined %}
240
  {% for disclaimer in disclaimers %}
241
  {{ disclaimer }}
242
  {% endfor %}
243
+ {% endif %}
prompts/faq.j2 CHANGED
@@ -31,24 +31,66 @@ PRODUCT NAME: {{ name }}
31
  REGION: {{ region }}
32
 
33
  TECHNICAL SPECIFICATIONS:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  {% for spec in specs %}
35
  - {{ spec }}
36
  {% endfor %}
 
37
 
38
  AUTHORIZED CLAIMS (use ONLY these):
 
 
 
 
 
 
 
 
39
  {% for claim in authorized_claims %}
40
  - {{ claim }}
41
  {% endfor %}
 
42
 
43
  PROHIBITED CLAIMS (never use these):
 
 
 
 
 
 
 
 
44
  {% for claim in prohibited_or_unsupported_claims %}
45
  - {{ claim }}
46
  {% endfor %}
 
47
 
48
  MANDATORY DISCLAIMERS (include verbatim at end):
 
 
 
 
 
49
  {% for disclaimer in disclaimers %}
50
  - {{ disclaimer }}
51
  {% endfor %}
 
52
 
53
  ═════════════════════════════════════════════════════════
54
  TARGET AUDIENCE PSYCHOLOGY
@@ -181,6 +223,12 @@ A: [Direct answer, 40-80 words, using only Product Data OR "Not stated in the pr
181
  ---
182
 
183
  **Disclaimers:**
 
 
 
 
 
184
  {% for disclaimer in disclaimers %}
185
  {{ disclaimer }}
186
  {% endfor %}
 
 
31
  REGION: {{ region }}
32
 
33
  TECHNICAL SPECIFICATIONS:
34
+ {% if specs is mapping %}
35
+ {% for category, items in specs.items() %}
36
+ {{ category }}:
37
+ {% if items is mapping %}
38
+ {% for subcategory, subitems in items.items() %}
39
+ {{ subcategory }}:
40
+ {% for item in subitems %}
41
+ - {{ item }}
42
+ {% endfor %}
43
+ {% endfor %}
44
+ {% else %}
45
+ {% for item in items %}
46
+ - {{ item }}
47
+ {% endfor %}
48
+ {% endif %}
49
+ {% endfor %}
50
+ {% else %}
51
  {% for spec in specs %}
52
  - {{ spec }}
53
  {% endfor %}
54
+ {% endif %}
55
 
56
  AUTHORIZED CLAIMS (use ONLY these):
57
+ {% if authorized_claims is mapping %}
58
+ {% for category, claims in authorized_claims.items() %}
59
+ {{ category }}:
60
+ {% for claim in claims %}
61
+ - {{ claim }}
62
+ {% endfor %}
63
+ {% endfor %}
64
+ {% else %}
65
  {% for claim in authorized_claims %}
66
  - {{ claim }}
67
  {% endfor %}
68
+ {% endif %}
69
 
70
  PROHIBITED CLAIMS (never use these):
71
+ {% if prohibited_or_unsupported_claims is mapping %}
72
+ {% for category, claims in prohibited_or_unsupported_claims.items() %}
73
+ {{ category }}:
74
+ {% for claim in claims %}
75
+ - {{ claim }}
76
+ {% endfor %}
77
+ {% endfor %}
78
+ {% else %}
79
  {% for claim in prohibited_or_unsupported_claims %}
80
  - {{ claim }}
81
  {% endfor %}
82
+ {% endif %}
83
 
84
  MANDATORY DISCLAIMERS (include verbatim at end):
85
+ {% if mandatory_statements is defined %}
86
+ {% for statement in mandatory_statements %}
87
+ - {{ statement }}
88
+ {% endfor %}
89
+ {% elif disclaimers is defined %}
90
  {% for disclaimer in disclaimers %}
91
  - {{ disclaimer }}
92
  {% endfor %}
93
+ {% endif %}
94
 
95
  ═════════════════════════════════════════════════════════
96
  TARGET AUDIENCE PSYCHOLOGY
 
223
  ---
224
 
225
  **Disclaimers:**
226
+ {% if mandatory_statements is defined %}
227
+ {% for statement in mandatory_statements %}
228
+ {{ statement }}
229
+ {% endfor %}
230
+ {% elif disclaimers is defined %}
231
  {% for disclaimer in disclaimers %}
232
  {{ disclaimer }}
233
  {% endfor %}
234
+ {% endif %}
test_render_fix.py CHANGED
@@ -5,7 +5,7 @@ from pathlib import Path
5
  from runner.render import load_product_yaml, render_prompt
6
 
7
  def test_product(product_id: str):
8
- """Test rendering a product."""
9
  print(f"\n{'='*60}")
10
  print(f"Testing: {product_id}")
11
  print(f"{'='*60}")
@@ -17,17 +17,20 @@ def test_product(product_id: str):
17
  print(f"βœ“ Loaded YAML: {product_data['name']}")
18
  print(f" Keys present: {sorted(product_data.keys())}")
19
 
20
- # Try rendering a template
21
- template = "digital_ad.j2"
22
- try:
23
- rendered = render_prompt(product_data, template, trap_flag=False)
24
- print(f"βœ“ Rendered template: {template}")
25
- print(f" Prompt length: {len(rendered)} characters")
26
- print(f"\n First 200 chars:\n {rendered[:200]}...")
27
- return True
28
- except Exception as e:
29
- print(f"βœ— Failed to render: {e}")
30
- return False
 
 
 
31
 
32
  if __name__ == "__main__":
33
  products = [
 
5
  from runner.render import load_product_yaml, render_prompt
6
 
7
  def test_product(product_id: str):
8
+ """Test rendering a product with all templates."""
9
  print(f"\n{'='*60}")
10
  print(f"Testing: {product_id}")
11
  print(f"{'='*60}")
 
17
  print(f"βœ“ Loaded YAML: {product_data['name']}")
18
  print(f" Keys present: {sorted(product_data.keys())}")
19
 
20
+ # Test all three updated templates
21
+ templates = ["digital_ad.j2", "faq.j2", "blog_post_promo.j2"]
22
+ results = {}
23
+
24
+ for template in templates:
25
+ try:
26
+ rendered = render_prompt(product_data, template, trap_flag=False)
27
+ print(f"βœ“ Rendered {template}: {len(rendered)} chars")
28
+ results[template] = True
29
+ except Exception as e:
30
+ print(f"βœ— Failed {template}: {e}")
31
+ results[template] = False
32
+
33
+ return all(results.values())
34
 
35
  if __name__ == "__main__":
36
  products = [