From 609740baff00114b26c6f111fdfdf8bdaf9db80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B2=BD=EB=AF=BC?= Date: Thu, 19 Mar 2026 12:52:45 +0900 Subject: [PATCH] Update handlers/common.py --- 03.Code/업로드용/handlers/common.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/03.Code/업로드용/handlers/common.py b/03.Code/업로드용/handlers/common.py index 8ff6b9e..08bc2ee 100644 --- a/03.Code/업로드용/handlers/common.py +++ b/03.Code/업로드용/handlers/common.py @@ -2,7 +2,8 @@ from dotenv import load_dotenv load_dotenv() # -*- coding: utf-8 -*- """ -공통 핸들러 유틸리티 +공통 핸들러 함수 +- Claude API 호출 - JSON/HTML 추출 """ @@ -12,7 +13,7 @@ import re import json import anthropic -# Claude API 클라이언트 +# Claude API 클라이언트 설정 client = anthropic.Anthropic( api_key=os.environ.get("ANTHROPIC_API_KEY") ) @@ -36,10 +37,10 @@ def extract_json(text: str) -> dict: text = text.split('```json')[1].split('```')[0] elif '```' in text: text = text.split('```')[1].split('```')[0] - + text = text.strip() - - # JSON 데이터 파싱 + + # JSON 파싱 시도 try: return json.loads(text) except json.JSONDecodeError: @@ -62,15 +63,16 @@ def extract_html(text: str) -> str: parts = text.split('```') if len(parts) >= 2: text = parts[1] - + text = text.strip() - - # )', text, re.IGNORECASE) if match: text = match.group(1) - + return text @@ -81,4 +83,4 @@ def load_prompt(prompts_dir: str, filename: str) -> str: with open(prompt_path, 'r', encoding='utf-8') as f: return f.read() except FileNotFoundError: - return None + return None \ No newline at end of file