diff --git a/BUILDER_APPS_MIGRATION.md b/BUILDER_APPS_MIGRATION.md index 1f719c4b..23465aeb 100644 --- a/BUILDER_APPS_MIGRATION.md +++ b/BUILDER_APPS_MIGRATION.md @@ -50,7 +50,19 @@ Das Projekt nutzt ein geteiltes `helpers.py`, das auf der alten OpenAI Python Li ```text openai==0.28.1 # weitere deps... +### 1.5 Python Syntax & F-Strings +Multi-Line f-Strings mit JSON-Beispielen (`{...}`) sind extrem fehleranfällig (Escaping, Einrückung). +* **Best Practice:** Komplexe JSON-Daten oder Strings **vorher** in Variablen speichern und dann einfügen. + ```python + # Schlecht: + prompt = f"""Daten: {json.dumps(data.get('nested'))}""" + + # Gut: + nested_json = json.dumps(data.get('nested')) + prompt = f"""Daten: {nested_json}""" ``` +* **Signaturen prüfen:** Shared Libraries (`helpers.py`) haben oft ältere Signaturen. + * Beispiel: `call_openai_chat` unterstützt oft kein `system_message` Argument. Stattdessen Prompt manuell zusammenbauen (`sys_instr + "\n\n" + prompt`). --- diff --git a/gtm_architect_orchestrator.py b/gtm_architect_orchestrator.py index 7e1da592..b1fee724 100644 --- a/gtm_architect_orchestrator.py +++ b/gtm_architect_orchestrator.py @@ -154,14 +154,17 @@ Output JSON format ONLY. """ # Fix: Prepend system instruction manually full_extraction_prompt = sys_instr + "\n\n" + extraction_prompt - extraction_response = call_openai_chat(full_extraction_prompt, json_mode=True) + 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""" PHASE 1-B: PORTFOLIO CONFLICT CHECK -New Product Features: {json.dumps(extraction_data.get('features'))} -New Product Constraints: {json.dumps(extraction_data.get('constraints'))} +New Product Features: {features_json} +New Product Constraints: {constraints_json} Existing Portfolio: 1. "Indoor Scrubber 50": Indoor cleaning, hard floor, supermarkets. @@ -174,8 +177,8 @@ Output JSON format ONLY. """ if lang == 'en' else f""" PHASE 1-B: PORTFOLIO CONFLICT CHECK -Neue Produkt-Features: {json.dumps(extraction_data.get('features'))} -Neue Produkt-Constraints: {json.dumps(extraction_data.get('constraints'))} +Neue Produkt-Features: {features_json} +Neue Produkt-Constraints: {constraints_json} Existierendes Portfolio: 1. "Indoor Scrubber 50": Innenreinigung, Hartboden, Supermärkte. @@ -188,7 +191,7 @@ 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, json_mode=True) + conflict_response = call_openai_chat(full_conflict_prompt, response_format_json=True) conflict_data = json.loads(conflict_response) final_result = {{**extraction_data, **conflict_data}} @@ -199,10 +202,13 @@ def discover_icps(data): lang = data.get('language', 'de') sys_instr = get_system_instruction(lang) + features_json = json.dumps(phase1_result.get('features')) + constraints_json = json.dumps(phase1_result.get('constraints')) + prompt = f""" PHASE 2: ICP DISCOVERY & DATA PROXIES -Based on the product features: {json.dumps(phase1_result.get('features'))} -And constraints: {json.dumps(phase1_result.get('constraints'))} +Based on the product features: {features_json} +And constraints: {constraints_json} Output JSON format ONLY: {{ @@ -211,8 +217,8 @@ Output JSON format ONLY: }} """ if lang == 'en' else f""" PHASE 2: ICP DISCOVERY & DATA PROXIES -Basierend auf Features: {json.dumps(phase1_result.get('features'))} -Und Constraints: {json.dumps(phase1_result.get('constraints'))} +Basierend auf Features: {features_json} +Und Constraints: {constraints_json} Output JSON format ONLY: {{ @@ -222,17 +228,18 @@ Output JSON format ONLY: """ # Fix: Prepend system instruction manually full_prompt = sys_instr + "\n\n" + prompt - response = call_openai_chat(full_prompt, json_mode=True) + response = call_openai_chat(full_prompt, response_format_json=True) print(response) def hunt_whales(data): phase2_result = data.get('phase2Result') lang = data.get('language', 'de') sys_instr = get_system_instruction(lang) - prompt = f"PHASE 3: WHALE HUNTING for {json.dumps(phase2_result.get('icps'))}. Identify 3-5 concrete DACH companies per industry and buying center roles. Output JSON ONLY." + icps_json = json.dumps(phase2_result.get('icps')) + prompt = f"PHASE 3: WHALE HUNTING for {icps_json}. Identify 3-5 concrete DACH companies per industry and buying center roles. Output JSON ONLY." # Fix: Prepend system instruction manually full_prompt = sys_instr + "\n\n" + prompt - response = call_openai_chat(full_prompt, json_mode=True) + response = call_openai_chat(full_prompt, response_format_json=True) print(response) def develop_strategy(data): @@ -240,16 +247,18 @@ def develop_strategy(data): phase1_result = data.get('phase1Result') lang = data.get('language', 'de') sys_instr = get_system_instruction(lang) - prompt = f"PHASE 4: STRATEGY Matrix for {json.dumps(phase3_result)}. Apply Hybrid logic. Output JSON ONLY." + phase3_json = json.dumps(phase3_result) + prompt = f"PHASE 4: STRATEGY Matrix for {phase3_json}. Apply Hybrid logic. Output JSON ONLY." # Fix: Prepend system instruction manually full_prompt = sys_instr + "\n\n" + prompt - response = call_openai_chat(full_prompt, json_mode=True) + response = call_openai_chat(full_prompt, response_format_json=True) print(response) def generate_assets(data): lang = data.get('language', 'de') sys_instr = get_system_instruction(lang) - prompt = f"PHASE 5: GTM STRATEGY REPORT Markdown. Use facts, TCO, ROI. Data: {json.dumps(data)}" + data_json = json.dumps(data) + prompt = f"PHASE 5: GTM STRATEGY REPORT Markdown. Use facts, TCO, ROI. Data: {data_json}" # Fix: Prepend system instruction manually full_prompt = sys_instr + "\n\n" + prompt response = call_openai_chat(full_prompt) @@ -258,10 +267,11 @@ def generate_assets(data): def generate_sales_enablement(data): lang = data.get('language', 'de') sys_instr = get_system_instruction(lang) - prompt = f"PHASE 6: Battlecards and MJ Prompts. Data: {json.dumps(data)}. Output JSON ONLY." + data_json = json.dumps(data) + prompt = f"PHASE 6: Battlecards and MJ Prompts. Data: {data_json}. Output JSON ONLY." # Fix: Prepend system instruction manually full_prompt = sys_instr + "\n\n" + prompt - response = call_openai_chat(full_prompt, json_mode=True) + response = call_openai_chat(full_prompt, response_format_json=True) print(response) def main(): @@ -296,4 +306,4 @@ def main(): print(json.dumps({"error": f"Unknown mode: {args.mode}"})) if __name__ == "__main__": - main() + main() \ No newline at end of file