Spaces:
Runtime error
Runtime error
File size: 3,880 Bytes
4293da0 | 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 | """
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!")
|