Spaces:
Runtime error
Runtime error
Download test_sap_pure_llm.py from CleanflowAI/cleanflowai: direct link, hf CLI and curl.
- Browser
- Download file 4.91 kB
-
https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/main/test_sap_pure_llm.py
- Command line
-
hf download hf://spaces/CleanflowAI/cleanflowai/test_sap_pure_llm.py
-
curl -L -o test_sap_pure_llm.py https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/main/test_sap_pure_llm.py
4.91 kB
| """ | |
| Test script for Pure LLM transformation system with SAP data. | |
| Tests that all mapped fields are preserved, not just standard CDF fields. | |
| """ | |
| 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_sap_pure_llm_transformation(): | |
| """Test Pure LLM transformation with SAP data to ensure all fields are preserved.""" | |
| # Initialize Pure LLM engine | |
| engine = PureTransformationEngine() | |
| # Load SAP test data | |
| with open('testing_files/sap_sales_orders.json', 'r') as f: | |
| sap_data = json.load(f) | |
| # Take first 3 records for testing | |
| sample_data = sap_data[:3] | |
| # 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 with SAP Data") | |
| print("=" * 60) | |
| print(f"Input data: {len(sample_data)} SAP records") | |
| print(f"Sample SAP columns: {list(sample_data[0].keys())}") | |
| print(f"Total SAP fields: {len(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(f"\nTotal mappings: {len(result.column_mappings)}") | |
| 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(f"Output columns: {len(output_data[0].keys()) if output_data else 0}") | |
| print() | |
| if output_data: | |
| print("Sample transformed record (first 10 fields):") | |
| sample_record = output_data[0] | |
| for i, (key, value) in enumerate(sample_record.items()): | |
| if i < 10: # Show first 10 fields | |
| print(f" {key}: {value}") | |
| else: | |
| print(f" ... and {len(sample_record) - 10} more fields") | |
| break | |
| print(f"\nAll output fields: {list(sample_record.keys())}") | |
| # Check if we preserved more fields than standard CDF | |
| standard_cdf_fields = [ | |
| "order_id", "order_date", "customer_id", "status", "currency", | |
| "total_amount", "notes", "item_id", "description", "quantity", | |
| "unit_price", "line_total", "tax_code" | |
| ] | |
| preserved_fields = len(sample_record.keys()) | |
| standard_fields = len(standard_cdf_fields) | |
| print(f"\nπ Field Preservation Analysis:") | |
| print(f"Standard CDF fields: {standard_fields}") | |
| print(f"Preserved fields: {preserved_fields}") | |
| print(f"Additional fields preserved: {preserved_fields - standard_fields}") | |
| if preserved_fields > standard_fields: | |
| print("β SUCCESS: More fields preserved than standard CDF schema!") | |
| print("β Pure LLM mapping is working correctly!") | |
| else: | |
| print("β οΈ WARNING: Only standard fields preserved - check mapping logic") | |
| else: | |
| print("β Transformation failed") | |
| if result.message: | |
| print(f"Error: {result.message}") | |
| # Cleanup | |
| engine.close() | |
| return result.success | |
| if __name__ == "__main__": | |
| success = test_sap_pure_llm_transformation() | |
| if success: | |
| print("\nπ SAP Pure LLM transformation test completed successfully!") | |
| else: | |
| print("\nπ₯ SAP Pure LLM transformation test failed!") | |