fix(gtm): Replace risky ternary operators in f-strings with explicit if/else blocks to fix SyntaxError

This commit is contained in:
2025-12-31 14:23:45 +00:00
parent a625e9e811
commit e2cfb4f2ae
2 changed files with 33 additions and 15 deletions

View File

@@ -131,7 +131,8 @@ def analyze_product(data):
lang = data.get('language', 'de')
sys_instr = get_system_instruction(lang)
extraction_prompt = f"""
if lang == 'en':
extraction_prompt = f"""
PHASE 1-A: TECHNICAL EXTRACTION
Input Product Description: "{product_input[:25000]}..."
@@ -141,7 +142,9 @@ Task:
3. Create a short raw analysis summary.
Output JSON format ONLY.
""" if lang == 'en' else f"""
"""
else:
extraction_prompt = f"""
PHASE 1-A: TECHNICAL EXTRACTION
Input Product Description: "{product_input[:25000]}..."
@@ -152,15 +155,18 @@ Aufgabe:
Output JSON format ONLY.
"""
# Fix: Prepend system instruction manually
full_extraction_prompt = sys_instr + "\n\n" + extraction_prompt
# Using response_format_json=True since helpers.py supports it (for logging/prompt hint)
extraction_response = call_openai_chat(full_extraction_prompt, response_format_json=True)
extraction_data = json.loads(extraction_response)
features_json = json.dumps(extraction_data.get('features'))
constraints_json = json.dumps(extraction_data.get('constraints'))
conflict_prompt = f"""
if lang == 'en':
conflict_prompt = f"""
PHASE 1-B: PORTFOLIO CONFLICT CHECK
New Product Features: {features_json}
@@ -174,7 +180,9 @@ Task:
Check if the new product overlaps significantly with existing ones (is it just a clone?).
Output JSON format ONLY.
""" if lang == 'en' else f"""
"""
else:
conflict_prompt = f"""
PHASE 1-B: PORTFOLIO CONFLICT CHECK
Neue Produkt-Features: {features_json}
@@ -189,6 +197,7 @@ Prüfe, ob das neue Produkt signifikant mit bestehenden Produkten überlappt (Is
Output JSON format ONLY.
"""
# Fix: Prepend system instruction manually
full_conflict_prompt = sys_instr + "\n\n" + conflict_prompt
conflict_response = call_openai_chat(full_conflict_prompt, response_format_json=True)
@@ -205,7 +214,8 @@ def discover_icps(data):
features_json = json.dumps(phase1_result.get('features'))
constraints_json = json.dumps(phase1_result.get('constraints'))
prompt = f"""
if lang == 'en':
prompt = f"""
PHASE 2: ICP DISCOVERY & DATA PROXIES
Based on the product features: {features_json}
And constraints: {constraints_json}
@@ -215,7 +225,9 @@ Output JSON format ONLY:
"icps": [ {{ "name": "Industry Name", "rationale": "Rationale" }} ],
"dataProxies": [ {{ "target": "Criteria", "method": "How" }} ]
}}
""" if lang == 'en' else f"""
"""
else:
prompt = f"""
PHASE 2: ICP DISCOVERY & DATA PROXIES
Basierend auf Features: {features_json}
Und Constraints: {constraints_json}
@@ -226,6 +238,7 @@ Output JSON format ONLY:
"dataProxies": [ {{ "target": "Kriterium", "method": "Methode" }} ]
}}
"""
# Fix: Prepend system instruction manually
full_prompt = sys_instr + "\n\n" + prompt
response = call_openai_chat(full_prompt, response_format_json=True)
@@ -283,11 +296,11 @@ def main():
try:
data = json.loads(sys.stdin.read())
except:
data = {}
data = {{}}
else:
data = {}
data = {{}}
modes = {
modes = {{
"analyze_product": analyze_product,
"discover_icps": discover_icps,
"hunt_whales": hunt_whales,
@@ -306,4 +319,4 @@ def main():
print(json.dumps({"error": f"Unknown mode: {args.mode}"}))
if __name__ == "__main__":
main()
main()