|
3 | 3 | arXiv 논문 큐레이션 스크립트 |
4 | 4 | - 화요일~토요일 아침 6시에 실행 |
5 | 5 | - 전날 발표된 논문 중 실무 적용 가능한 TOP 5 선정 |
| 6 | +- Claude를 이용해 요약을 한글로 번역 |
6 | 7 | - GitHub에 커밋 및 푸시 |
7 | 8 | """ |
8 | 9 |
|
|
12 | 13 | import subprocess |
13 | 14 | from datetime import datetime, timedelta |
14 | 15 | import time |
| 16 | +import os |
15 | 17 |
|
16 | 18 | CATEGORIES = ['cs.AI', 'cs.LG', 'cs.CV', 'cs.NI', 'cs.CR'] |
17 | 19 |
|
@@ -68,6 +70,51 @@ def fetch_papers(target_date): |
68 | 70 |
|
69 | 71 | return all_papers |
70 | 72 |
|
| 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 | + |
71 | 118 | def score_paper(paper): |
72 | 119 | """논문의 실무 적용 가능성과 주목도를 점수화""" |
73 | 120 | score = 0 |
@@ -177,8 +224,10 @@ def generate_report(target_date, top_papers): |
177 | 224 | report += f"- **점수**: {paper['score']}점\n" |
178 | 225 |
|
179 | 226 | 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" |
182 | 231 |
|
183 | 232 | report += f"- **링크**: https://arxiv.org/abs/{paper['arxiv_id']}\n\n" |
184 | 233 |
|
|
0 commit comments