Spaces:
Runtime error
Runtime error
File size: 4,911 Bytes
330ad16 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | """
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!")
|