File size: 5,758 Bytes
4aa05c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# test_basic_integration.py - ๊ธฐ๋ณธ ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ (PyTorch ์—†์ด)
import os
import sys
import time
from datetime import datetime

def test_basic_imports():
    """๊ธฐ๋ณธ ๋ชจ๋“ˆ import ํ…Œ์ŠคํŠธ"""
    print("[IMPORT] ๊ธฐ๋ณธ ๋ชจ๋“ˆ import ํ…Œ์ŠคํŠธ...")
    
    results = {}
    
    # 1. LLM ํ”„๋กœ์„ธ์„œ์˜ ๊ณ„์‚ฐ ์—”์ง„ ๋ถ€๋ถ„๋งŒ ํ…Œ์ŠคํŠธ
    try:
        from llm_processor import TaxRuleEngine
        engine = TaxRuleEngine()
        
        # ๊ฐ„๋‹จํ•œ ๊ณ„์‚ฐ ํ…Œ์ŠคํŠธ
        test_property = {
            'acquisition_value': 1000000000,  # 10์–ต์›
            'location': '์„œ์šธํŠน๋ณ„์‹œ ๊ฐ•๋‚จ๊ตฌ',
            'housing_list': [{'id': 1}, {'id': 2}]  # ๊ธฐ์กด 2์ฃผํƒ
        }
        
        result = engine.calculate_comprehensive_tax(test_property)
        if result and result['tax_amount'] > 0:
            print(f"[OK] ์ทจ๋“์„ธ ๊ณ„์‚ฐ ์—”์ง„: {result['tax_amount']:,}์›")
            results['tax_engine'] = True
        else:
            print("[ERROR] ์ทจ๋“์„ธ ๊ณ„์‚ฐ ์‹คํŒจ")
            results['tax_engine'] = False
            
    except Exception as e:
        print(f"[ERROR] ์ทจ๋“์„ธ ๊ณ„์‚ฐ ์—”์ง„ import ์‹คํŒจ: {e}")
        results['tax_engine'] = False
    
    # 2. ๊ธฐ๋ณธ ํŒŒ์ผ๋“ค ์กด์žฌ ํ™•์ธ
    required_files = [
        'llm_processor.py',
        'rag_system.py', 
        'app.py',
        'config.py',
        'law_fetcher.py'
    ]
    
    missing_files = []
    for file in required_files:
        if not os.path.exists(file):
            missing_files.append(file)
    
    if not missing_files:
        print("[OK] ๋ชจ๋“  ํ•„์ˆ˜ ํŒŒ์ผ ์กด์žฌ")
        results['files'] = True
    else:
        print(f"[ERROR] ๋ˆ„๋ฝ๋œ ํŒŒ์ผ: {missing_files}")
        results['files'] = False
    
    # 3. ์„ค์ • ํŒŒ์ผ ๋กœ๋“œ ํ…Œ์ŠคํŠธ
    try:
        from config import RAG_CONFIG
        if RAG_CONFIG and 'embedding_models' in RAG_CONFIG:
            print("[OK] ์„ค์ • ํŒŒ์ผ ๋กœ๋“œ ์™„๋ฃŒ")
            results['config'] = True
        else:
            print("[ERROR] ์„ค์ • ํŒŒ์ผ ๋‚ด์šฉ ๋ถˆ์™„์ „")
            results['config'] = False
    except Exception as e:
        print(f"[ERROR] ์„ค์ • ํŒŒ์ผ ๋กœ๋“œ ์‹คํŒจ: {e}")
        results['config'] = False
    
    # 4. LLM ํ”„๋กœ์„ธ์„œ์˜ ์ •๋ณด ์ถ”์ถœ ๊ธฐ๋Šฅ ํ…Œ์ŠคํŠธ
    try:
        from llm_processor import LLMProcessor
        processor = LLMProcessor()
        
        # ๋ชจ๋ธ ๋กœ๋”ฉ ์—†์ด ์ •๋ณด ์ถ”์ถœ๋งŒ ํ…Œ์ŠคํŠธ
        test_input = "๊ฐ•๋‚จ๊ตฌ์—์„œ 10์–ต์› ์•„ํŒŒํŠธ๋ฅผ ๊ตฌ๋งคํ•˜๋Š”๋ฐ ๊ธฐ์กด์— 2์ฃผํƒ ๋ณด์œ "
        property_info = processor.extract_property_info(test_input)
        
        if (property_info.get('acquisition_value') == 1000000000 and
            '๊ฐ•๋‚จ๊ตฌ' in property_info.get('location', '') and
            len(property_info.get('housing_list', [])) == 2):
            print("[OK] ์ •๋ณด ์ถ”์ถœ ๊ธฐ๋Šฅ ์ •์ƒ")
            results['extraction'] = True
        else:
            print(f"[PARTIAL] ์ •๋ณด ์ถ”์ถœ ๋ถ€๋ถ„์  ์„ฑ๊ณต: {property_info}")
            results['extraction'] = True  # ๋ถ€๋ถ„์ ์ด๋ผ๋„ ์ž‘๋™ํ•˜๋ฉด OK
            
    except Exception as e:
        print(f"[ERROR] ์ •๋ณด ์ถ”์ถœ ํ…Œ์ŠคํŠธ ์‹คํŒจ: {e}")
        results['extraction'] = False
    
    return results

def test_web_integration():
    """์›น ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ (Flask ์•ฑ ๊ตฌ์กฐ ํ™•์ธ)"""
    print("[WEB] ์›น ํ†ตํ•ฉ ๊ตฌ์กฐ ํ…Œ์ŠคํŠธ...")
    
    try:
        # app.py์˜ ๊ธฐ๋ณธ ๊ตฌ์กฐ ํ™•์ธ
        with open('app.py', 'r', encoding='utf-8') as f:
            app_content = f.read()
        
        required_patterns = [
            'Flask',
            '/api/web/chat',
            'search_tax_law'
        ]
        
        missing_patterns = []
        for pattern in required_patterns:
            if pattern not in app_content:
                missing_patterns.append(pattern)
        
        if not missing_patterns:
            print("[OK] ์›น ์•ฑ ๊ตฌ์กฐ ํ™•์ธ ์™„๋ฃŒ")
            return True
        else:
            print(f"[ERROR] ์›น ์•ฑ์—์„œ ๋ˆ„๋ฝ๋œ ํŒจํ„ด: {missing_patterns}")
            return False
            
    except Exception as e:
        print(f"[ERROR] ์›น ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ ์‹คํŒจ: {e}")
        return False

def main():
    """๋ฉ”์ธ ํ…Œ์ŠคํŠธ"""
    print("[MAIN] ๊ธฐ๋ณธ ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ ์‹œ์ž‘ (PyTorch ์—†์ด)")
    print("=" * 60)
    print(f"[TIME] ํ…Œ์ŠคํŠธ ์‹œ๊ฐ„: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
    print("=" * 60)
    
    # 1. ๊ธฐ๋ณธ import ํ…Œ์ŠคํŠธ
    print("\n[1] ๊ธฐ๋ณธ ๋ชจ๋“ˆ ํ…Œ์ŠคํŠธ")
    print("-" * 30)
    import_results = test_basic_imports()
    
    # 2. ์›น ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ
    print("\n[2] ์›น ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ")
    print("-" * 30)
    web_result = test_web_integration()
    
    # 3. ๊ฒฐ๊ณผ ์ •๋ฆฌ
    print("\n" + "=" * 60)
    print("[SUMMARY] ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ")
    print("=" * 60)
    
    all_results = {**import_results, 'web_integration': web_result}
    total_tests = len(all_results)
    passed_tests = sum(all_results.values())
    
    print(f"[PASS] ํ†ต๊ณผ: {passed_tests}/{total_tests}")
    print(f"[FAIL] ์‹คํŒจ: {total_tests - passed_tests}/{total_tests}")
    
    for test_name, result in all_results.items():
        status = "PASS" if result else "FAIL"
        print(f"   {test_name}: {status}")
    
    if passed_tests >= total_tests * 0.7:  # 70% ์ด์ƒ ํ†ต๊ณผํ•˜๋ฉด ์„ฑ๊ณต
        print(f"\n[SUCCESS] ๊ธฐ๋ณธ ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ ํ†ต๊ณผ! ({passed_tests}/{total_tests})")
        print("[INFO] HuggingFace Spaces์—์„œ๋Š” GPU ํ™˜๊ฒฝ์—์„œ ์ •์ƒ ์ž‘๋™ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.")
        return True
    else:
        print(f"\n[WARNING] ๊ธฐ๋ณธ ํ…Œ์ŠคํŠธ์—์„œ ๋ฌธ์ œ ๋ฐœ๊ฒฌ. ์ˆ˜์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
        return False

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)