feat: Google Drive API 인증 및 에러 처리 개선

This commit is contained in:
2025-08-28 11:58:36 +09:00
parent 59d213ab4a
commit f0ddc5aebe
4 changed files with 66 additions and 15 deletions

View File

@@ -28,9 +28,28 @@ class AIAgent:
# 도구들 초기화
self.web_scraper = WebScraper(config_path)
self.drive_uploader = GoogleDriveUploader(config_path)
self.simple_saver = SimpleDriveSaver(self.config['data_storage']['drive_mount_path'])
# Google Drive API는 선택 사항: 자격증명 파일이 존재할 때만 활성화
self.drive_uploader = None
try:
drive_folder_id = self.config.get('google_drive_folder_id', '').strip()
creds_path = self.config.get('google_credentials_path', '').strip()
has_valid_folder = bool(drive_folder_id) and drive_folder_id != 'YOUR_GOOGLE_DRIVE_FOLDER_ID'
has_creds_file = bool(creds_path) and __import__('os').path.isfile(creds_path)
if has_valid_folder and has_creds_file:
self.drive_uploader = GoogleDriveUploader(config_path)
else:
reason = []
if not has_valid_folder:
reason.append('folder_id 미설정')
if not has_creds_file:
reason.append('credentials 파일 없음')
print(f"Google Drive API 비활성화 ({', '.join(reason)}) — SimpleDriveSaver만 사용")
except Exception as e:
# 어떤 이유로든 초기화 실패 시 API 도구는 비활성화하고 계속 진행
print(f"Google Drive API 초기화 실패: {e} — SimpleDriveSaver만 사용")
# LangChain 도구 정의
self.tools = [
Tool(
@@ -38,11 +57,6 @@ class AIAgent:
func=self.scrape_web,
description="웹사이트에서 정보를 수집합니다. URL을 입력하세요."
),
Tool(
name="GoogleDriveUploader",
func=self.upload_to_drive_api,
description="Google Drive API를 사용하여 데이터를 업로드합니다. 데이터와 파일명을 입력하세요."
),
Tool(
name="SimpleDriveSaver",
func=self.save_to_drive_simple,
@@ -50,6 +64,16 @@ class AIAgent:
)
]
# Google Drive API 도구는 사용 가능할 때만 추가
if self.drive_uploader is not None:
self.tools.append(
Tool(
name="GoogleDriveUploader",
func=self.upload_to_drive_api,
description="Google Drive API를 사용하여 데이터를 업로드합니다. 데이터(JSON)|파일명 형식으로 입력하세요."
)
)
# 메모리
self.memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)