v4:코드모듈화_20260123

This commit is contained in:
2026-02-20 11:34:02 +09:00
parent a990081287
commit 17e639ed40
24 changed files with 5412 additions and 1054 deletions

View File

@@ -1,17 +1,30 @@
"""API 키 관리 - api_keys.json에서 읽기"""
import json
"""API 키 관리 - .env 파일에서 읽기"""
import os
from pathlib import Path
def load_api_keys():
"""프로젝트 폴더의 api_keys.json에서 API 키 로딩"""
search_path = Path(__file__).resolve().parent
for _ in range(5):
key_file = search_path / 'api_keys.json'
if key_file.exists():
with open(key_file, 'r', encoding='utf-8') as f:
return json.load(f)
search_path = search_path.parent
print("warning: api_keys.json not found")
return {}
"""프로젝트 폴더의 .env에서 API 키 로딩"""
# python-dotenv 있으면 사용
try:
from dotenv import load_dotenv
env_path = Path(__file__).resolve().parent / '.env'
load_dotenv(env_path)
except ImportError:
# python-dotenv 없으면 수동 파싱
env_path = Path(__file__).resolve().parent / '.env'
if env_path.exists():
with open(env_path, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if line and not line.startswith('#') and '=' in line:
key, _, value = line.partition('=')
os.environ.setdefault(key.strip(), value.strip())
return {
'CLAUDE_API_KEY': os.getenv('CLAUDE_API_KEY', ''),
'GPT_API_KEY': os.getenv('GPT_API_KEY', ''),
'GEMINI_API_KEY': os.getenv('GEMINI_API_KEY', ''),
'PERPLEXITY_API_KEY': os.getenv('PERPLEXITY_API_KEY', ''),
}
API_KEYS = load_api_keys()