#!/usr/bin/env python3 """ Test script for Step 5 with orchestrator's direct step execution """ import asyncio import sys import os import time # Add the backend directory to the path sys.path.append(os.path.dirname(os.path.abspath(__file__))) async def test_step5_orchestrator_direct(): """Test Step 5 with orchestrator's direct step execution.""" print("๐Ÿงช Testing Step 5 with orchestrator's direct step execution") try: # Import orchestrator and Step 5 from services.calendar_generation_datasource_framework.prompt_chaining.orchestrator import PromptChainOrchestrator from services.calendar_generation_datasource_framework.prompt_chaining.steps.phase2.step5_implementation import ContentPillarDistributionStep # Create orchestrator print("โœ… Creating orchestrator...") orchestrator = PromptChainOrchestrator() print("โœ… Orchestrator created successfully") # Get Step 5 from orchestrator step5 = orchestrator.steps["step_05"] print(f"โœ… Got Step 5 from orchestrator: {type(step5)}") # Create context exactly as the orchestrator does context = { "user_id": 1, "strategy_id": 1, "calendar_type": "monthly", "industry": "technology", "business_size": "sme", "user_data": { "user_id": 1, "strategy_id": 1, "industry": "technology", "onboarding_data": { "posting_preferences": { "daily": 2, "weekly": 10, "monthly": 40 }, "posting_days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], "optimal_times": ["09:00", "12:00", "15:00", "18:00", "20:00"] }, "strategy_data": { "content_pillars": [ "AI and Machine Learning", "Digital Transformation", "Innovation and Technology Trends", "Business Strategy and Growth" ], "business_objectives": [ "Increase brand awareness by 40%", "Generate 500 qualified leads per month", "Establish thought leadership in AI/ML space" ] } }, "step_results": { "step_04": { "stepNumber": 4, "stepName": "Calendar Framework & Timeline", "results": { "calendarStructure": { "type": "monthly", "total_weeks": 4, "posting_days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], "posting_frequency": { "daily": 2, "weekly": 10, "monthly": 40 }, "industry": "technology", "business_size": "sme" } }, "qualityScore": 1.0, "executionTime": "2.9s" } }, "quality_scores": {}, "current_step": 5, "phase": "phase_2_structure" } # Test Step 5 execution with timing print("๐Ÿ”„ Executing Step 5 with orchestrator's step...") start_time = time.time() result = await step5.run(context) execution_time = time.time() - start_time print(f"โฑ๏ธ Step 5 execution time: {execution_time:.2f} seconds") if result: print("โœ… Step 5 executed successfully!") print(f"Status: {result.get('status', 'unknown')}") print(f"Quality Score: {result.get('quality_score', 0)}") print(f"Execution Time: {result.get('execution_time', 'unknown')}") if result.get('status') == 'error': print(f"โŒ Step 5 Error: {result.get('error_message', 'Unknown error')}") else: print("๐Ÿ“Š Step 5 Results:") step_result = result.get('result', {}) print(f" - Pillar Mapping: {step_result.get('pillarMapping', {}).get('distribution_balance', 0):.1%} balance") print(f" - Theme Development: {step_result.get('themeDevelopment', {}).get('variety_score', 0):.1%} variety") print(f" - Strategic Validation: {step_result.get('strategicValidation', {}).get('alignment_score', 0):.1%} alignment") print(f" - Diversity Assurance: {step_result.get('diversityAssurance', {}).get('diversity_score', 0):.1%} diversity") else: print("โŒ Step 5 returned None") except Exception as e: print(f"โŒ Error testing Step 5: {e}") import traceback print(f"๐Ÿ“‹ Traceback: {traceback.format_exc()}") if __name__ == "__main__": asyncio.run(test_step5_orchestrator_direct())