📦 Initialize Geulbeot structure and merge Prompts & test projects
This commit is contained in:
30
03. Code/geulbeot_9th/api_config.py
Normal file
30
03. Code/geulbeot_9th/api_config.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""API 키 관리 - .env 파일에서 읽기"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
def load_api_keys():
|
||||
"""프로젝트 폴더의 .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()
|
||||
Reference in New Issue
Block a user