""" Test script for Pure LLM transformation system. """ import json import logging from dotenv import load_dotenv from mapper.transformation_engine_pure import PureTransformationEngine from mapper.models import TransformationRequest from mapper.data_processor import FileFormat # Load environment variables load_dotenv() # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) def test_pure_llm_transformation(): """Test Pure LLM transformation with sample data.""" # Initialize Pure LLM engine engine = PureTransformationEngine() # Sample unknown ERP data (could be from any system) sample_data = [ { "order_num": "ORD-001", "order_dt": "2025-01-15", "cust_ref": "CUST-123", "order_amt": 1250.00, "order_status": "confirmed", "curr_code": "USD", "notes_field": "Rush order", "prod_id": "PROD-456", "prod_desc": "Widget A", "qty_ordered": 5, "unit_cost": 250.00, "line_amt": 1250.00, "tax_id": "TAX001" }, { "order_num": "ORD-002", "order_dt": "2025-01-16", "cust_ref": "CUST-456", "order_amt": 750.50, "order_status": "pending", "curr_code": "USD", "notes_field": "Standard order", "prod_id": "PROD-789", "prod_desc": "Widget B", "qty_ordered": 3, "unit_cost": 250.17, "line_amt": 750.50, "tax_id": "TAX002" } ] # Convert to JSON bytes json_bytes = json.dumps(sample_data).encode('utf-8') # Create transformation request (unknown ERP and entity) request = TransformationRequest( auto_select_erp=True, # Unknown ERP auto_select_entity=True, # Unknown entity entity=None, # Will default to sales_orders erp=None, # Unknown file_data=json_bytes, file_format=FileFormat.JSON ) print("šŸš€ Testing Pure LLM Transformation System") print("=" * 50) print(f"Input data: {len(sample_data)} records") print(f"Sample columns: {list(sample_data[0].keys())}") print() # Perform transformation result = engine.transform(request) # Display results print("šŸ“Š Transformation Results:") print(f"Success: {result.success}") print(f"Detected ERP: {result.detected_erp}") print(f"Detected Entity: {result.detected_entity}") print(f"Transformation Mode: {result.transformation_mode}") print(f"Confidence Score: {result.confidence_score}") print(f"Message: {result.message}") print() if result.success and result.column_mappings: print("šŸ”„ Column Mappings Generated:") for source, target in result.column_mappings.items(): print(f" {source} → {target}") print() if result.data is not None: # Convert to dict for display output_data = engine.data_processor.to_dict(result.data) print(f"āœ… Transformed Data: {len(output_data)} records") print("Sample transformed record:") if output_data: for key, value in list(output_data[0].items())[:5]: # Show first 5 fields print(f" {key}: {value}") print(" ...") else: print("āŒ Transformation failed") if result.message: print(f"Error: {result.message}") # Cleanup engine.close() return result.success if __name__ == "__main__": success = test_pure_llm_transformation() if success: print("\nšŸŽ‰ Pure LLM transformation test completed successfully!") else: print("\nšŸ’„ Pure LLM transformation test failed!")