mirror of
https://github.com/hwanny1128/HGZero.git
synced 2025-12-06 11:26:25 +00:00
246 lines
7.5 KiB
Python
246 lines
7.5 KiB
Python
"""
|
|
Vector DB 통합 시스템 설정 검증 스크립트
|
|
|
|
사용법: python scripts/validate_setup.py
|
|
"""
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
from typing import List, Tuple
|
|
|
|
# 프로젝트 루트 디렉토리
|
|
project_root = Path(__file__).parent.parent
|
|
|
|
|
|
def check_file_exists(file_path: Path, description: str) -> bool:
|
|
"""파일 존재 여부 확인"""
|
|
exists = file_path.exists()
|
|
status = "✓" if exists else "✗"
|
|
print(f" {status} {description}: {file_path.name}")
|
|
return exists
|
|
|
|
|
|
def check_directory_exists(dir_path: Path, description: str) -> bool:
|
|
"""디렉토리 존재 여부 확인"""
|
|
exists = dir_path.exists() and dir_path.is_dir()
|
|
status = "✓" if exists else "✗"
|
|
print(f" {status} {description}: {dir_path.name}/")
|
|
return exists
|
|
|
|
|
|
def check_python_version() -> bool:
|
|
"""Python 버전 확인"""
|
|
version = sys.version_info
|
|
is_valid = version.major == 3 and version.minor >= 9
|
|
status = "✓" if is_valid else "✗"
|
|
print(f" {status} Python 버전: {version.major}.{version.minor}.{version.micro}")
|
|
if not is_valid:
|
|
print(f" → Python 3.9 이상이 필요합니다")
|
|
return is_valid
|
|
|
|
|
|
def check_dependencies() -> bool:
|
|
"""필수 패키지 설치 확인"""
|
|
required_packages = [
|
|
"fastapi",
|
|
"uvicorn",
|
|
"psycopg2",
|
|
"openai",
|
|
"anthropic",
|
|
"azure.search.documents",
|
|
"pydantic",
|
|
"pyyaml",
|
|
"tenacity"
|
|
]
|
|
|
|
missing_packages = []
|
|
for package in required_packages:
|
|
try:
|
|
__import__(package.replace("-", "_").split(".")[0])
|
|
print(f" ✓ {package}")
|
|
except ImportError:
|
|
print(f" ✗ {package}")
|
|
missing_packages.append(package)
|
|
|
|
if missing_packages:
|
|
print(f"\n → 누락된 패키지를 설치하세요: pip install {' '.join(missing_packages)}")
|
|
return False
|
|
return True
|
|
|
|
|
|
def check_env_variables() -> Tuple[bool, List[str]]:
|
|
"""환경 변수 설정 확인"""
|
|
required_vars = [
|
|
"POSTGRES_HOST",
|
|
"POSTGRES_PORT",
|
|
"POSTGRES_DATABASE",
|
|
"POSTGRES_USER",
|
|
"POSTGRES_PASSWORD",
|
|
"AZURE_OPENAI_API_KEY",
|
|
"AZURE_OPENAI_ENDPOINT",
|
|
"AZURE_SEARCH_ENDPOINT",
|
|
"AZURE_SEARCH_API_KEY",
|
|
"CLAUDE_API_KEY"
|
|
]
|
|
|
|
# .env 파일 확인
|
|
env_file = project_root / ".env"
|
|
if env_file.exists():
|
|
print(f" ✓ .env 파일 존재")
|
|
# .env 파일 로드 시뮬레이션
|
|
with open(env_file, 'r', encoding='utf-8') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if '=' in line and not line.startswith('#'):
|
|
key, value = line.split('=', 1)
|
|
if value and value != f"your_{key.lower()}_here":
|
|
os.environ[key] = value
|
|
else:
|
|
print(f" ✗ .env 파일 없음")
|
|
print(f" → .env.example을 .env로 복사하고 실제 값으로 수정하세요")
|
|
|
|
missing_vars = []
|
|
for var in required_vars:
|
|
value = os.environ.get(var, "")
|
|
has_value = bool(value) and not value.startswith("your_")
|
|
|
|
if has_value:
|
|
# API 키는 앞 4자리만 표시
|
|
if "KEY" in var or "PASSWORD" in var:
|
|
display_value = value[:4] + "..." if len(value) > 4 else "***"
|
|
else:
|
|
display_value = value
|
|
print(f" ✓ {var}: {display_value}")
|
|
else:
|
|
print(f" ✗ {var}: 설정 필요")
|
|
missing_vars.append(var)
|
|
|
|
return len(missing_vars) == 0, missing_vars
|
|
|
|
|
|
def check_data_files() -> bool:
|
|
"""샘플 데이터 파일 확인"""
|
|
data_dir = project_root.parent / "design/aidata"
|
|
meet_ref_file = project_root.parent / "design/meet-ref.json"
|
|
|
|
all_exists = True
|
|
|
|
# 용어 데이터 파일
|
|
term_files = ["terms-01.json", "terms-02.json", "terms-03.json", "terms-04.json"]
|
|
for filename in term_files:
|
|
file_path = data_dir / filename
|
|
exists = file_path.exists()
|
|
status = "✓" if exists else "✗"
|
|
print(f" {status} {filename}")
|
|
all_exists = all_exists and exists
|
|
|
|
# 관련 문서 데이터 파일
|
|
exists = meet_ref_file.exists()
|
|
status = "✓" if exists else "✗"
|
|
print(f" {status} meet-ref.json")
|
|
all_exists = all_exists and exists
|
|
|
|
if not all_exists:
|
|
print(f"\n → 데이터 파일이 design/ 디렉토리에 있는지 확인하세요")
|
|
|
|
return all_exists
|
|
|
|
|
|
def main():
|
|
"""메인 검증 함수"""
|
|
print("\n" + "=" * 70)
|
|
print("Vector DB 통합 시스템 설정 검증")
|
|
print("=" * 70 + "\n")
|
|
|
|
results = {}
|
|
|
|
# 1. Python 버전 확인
|
|
print("1. Python 버전 확인")
|
|
results["python"] = check_python_version()
|
|
print()
|
|
|
|
# 2. 프로젝트 구조 확인
|
|
print("2. 프로젝트 구조 확인")
|
|
structure_checks = [
|
|
(project_root / "config.yaml", "설정 파일"),
|
|
(project_root / "requirements.txt", "의존성 파일"),
|
|
(project_root / "README.md", "문서"),
|
|
(project_root / "src", "소스 디렉토리"),
|
|
(project_root / "src/models", "모델 디렉토리"),
|
|
(project_root / "src/db", "DB 디렉토리"),
|
|
(project_root / "src/services", "서비스 디렉토리"),
|
|
(project_root / "src/api", "API 디렉토리"),
|
|
(project_root / "scripts", "스크립트 디렉토리"),
|
|
(project_root / "tests", "테스트 디렉토리")
|
|
]
|
|
|
|
structure_ok = True
|
|
for path, desc in structure_checks:
|
|
if path.is_dir():
|
|
structure_ok = check_directory_exists(path, desc) and structure_ok
|
|
else:
|
|
structure_ok = check_file_exists(path, desc) and structure_ok
|
|
|
|
results["structure"] = structure_ok
|
|
print()
|
|
|
|
# 3. 의존성 패키지 확인
|
|
print("3. 의존성 패키지 확인")
|
|
results["dependencies"] = check_dependencies()
|
|
print()
|
|
|
|
# 4. 환경 변수 확인
|
|
print("4. 환경 변수 확인")
|
|
env_ok, missing_vars = check_env_variables()
|
|
results["environment"] = env_ok
|
|
print()
|
|
|
|
# 5. 데이터 파일 확인
|
|
print("5. 샘플 데이터 파일 확인")
|
|
results["data_files"] = check_data_files()
|
|
print()
|
|
|
|
# 결과 요약
|
|
print("=" * 70)
|
|
print("검증 결과 요약")
|
|
print("=" * 70)
|
|
|
|
all_passed = all(results.values())
|
|
|
|
for category, passed in results.items():
|
|
status = "✓ 통과" if passed else "✗ 실패"
|
|
print(f" {status}: {category}")
|
|
|
|
print()
|
|
|
|
if all_passed:
|
|
print("🎉 모든 검증을 통과했습니다!")
|
|
print()
|
|
print("다음 단계:")
|
|
print(" 1. 데이터베이스 초기화: python scripts/load_terms.py")
|
|
print(" 2. 관련자료 로딩: python scripts/load_documents.py")
|
|
print(" 3. API 서버 실행: python -m src.api.main")
|
|
print(" 4. API 문서 확인: http://localhost:8000/docs")
|
|
else:
|
|
print("⚠️ 일부 검증에 실패했습니다.")
|
|
print()
|
|
print("실패한 항목을 확인하고 수정한 후 다시 실행하세요.")
|
|
|
|
if not results["dependencies"]:
|
|
print("\n의존성 설치 명령:")
|
|
print(" pip install -r requirements.txt")
|
|
|
|
if not results["environment"]:
|
|
print("\n환경 변수 설정 방법:")
|
|
print(" 1. .env.example을 .env로 복사")
|
|
print(" 2. .env 파일을 열어 실제 값으로 수정")
|
|
|
|
print()
|
|
print("=" * 70)
|
|
|
|
return 0 if all_passed else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|