Skip to content

Commit 21ae399

Browse files
author
Jerry
committed
feat: add Claude Korean translation to arxiv_curator.py
1 parent a589a98 commit 21ae399

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

arxiv_curator.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
arXiv 논문 큐레이션 스크립트
44
- 화요일~토요일 아침 6시에 실행
55
- 전날 발표된 논문 중 실무 적용 가능한 TOP 5 선정
6+
- Claude를 이용해 요약을 한글로 번역
67
- GitHub에 커밋 및 푸시
78
"""
89

@@ -12,6 +13,7 @@
1213
import subprocess
1314
from datetime import datetime, timedelta
1415
import time
16+
import os
1517

1618
CATEGORIES = ['cs.AI', 'cs.LG', 'cs.CV', 'cs.NI', 'cs.CR']
1719

@@ -68,6 +70,51 @@ def fetch_papers(target_date):
6870

6971
return all_papers
7072

73+
def translate_to_korean(text):
74+
"""Claude API를 이용해 영문 요약을 한글로 번역"""
75+
if not text or len(text.strip()) == 0:
76+
return ""
77+
78+
try:
79+
# OpenRouter API 사용 (Claude 3.5 Haiku)
80+
api_key = os.getenv('OPENROUTER_API_KEY')
81+
if not api_key:
82+
print("⚠️ OPENROUTER_API_KEY 환경 변수 없음, 원문 그대로 사용")
83+
return text[:300] + "..." if len(text) > 300 else text
84+
85+
url = 'https://openrouter.ai/api/v1/chat/completions'
86+
headers = {
87+
'Authorization': f'Bearer {api_key}',
88+
'Content-Type': 'application/json'
89+
}
90+
91+
# 텍스트 길이 제한 (번역 시간 단축)
92+
text_to_translate = text[:500] if len(text) > 500 else text
93+
94+
payload = {
95+
'model': 'anthropic/claude-3.5-haiku',
96+
'messages': [{
97+
'role': 'user',
98+
'content': f'다음 영문 학술 논문 요약을 한글로 간결하게 번역해줘. 300자 이내로 요약해줘:\n\n{text_to_translate}'
99+
}],
100+
'temperature': 0.3,
101+
'max_tokens': 300
102+
}
103+
104+
response = requests.post(url, headers=headers, json=payload, timeout=10)
105+
106+
if response.status_code == 200:
107+
result = response.json()
108+
translated = result['choices'][0]['message']['content'].strip()
109+
return translated
110+
else:
111+
print(f"⚠️ Claude API 오류 (상태: {response.status_code}), 원문 사용")
112+
return text[:300] + "..." if len(text) > 300 else text
113+
114+
except Exception as e:
115+
print(f"⚠️ 번역 오류: {str(e)[:50]}, 원문 사용")
116+
return text[:300] + "..." if len(text) > 300 else text
117+
71118
def score_paper(paper):
72119
"""논문의 실무 적용 가능성과 주목도를 점수화"""
73120
score = 0
@@ -177,8 +224,10 @@ def generate_report(target_date, top_papers):
177224
report += f"- **점수**: {paper['score']}\n"
178225

179226
if paper['summary']:
180-
summary = paper['summary'][:250] + "..." if len(paper['summary']) > 250 else paper['summary']
181-
report += f"- **요약**: {summary}\n"
227+
# Claude를 이용해 한글로 번역
228+
print(f" 📝 {i}번 논문 요약 번역 중...")
229+
translated_summary = translate_to_korean(paper['summary'])
230+
report += f"- **요약 (한글)**: {translated_summary}\n"
182231

183232
report += f"- **링크**: https://arxiv.org/abs/{paper['arxiv_id']}\n\n"
184233

0 commit comments

Comments
 (0)