mirror of
https://github.com/hwanny1128/HGZero.git
synced 2026-06-13 04:49:11 +00:00
Feat: AI 요약 재생성 API 구현
This commit is contained in:
@@ -133,6 +133,76 @@ class ClaudeService:
|
||||
logger.error(f"제안사항 분석 실패: {e}", exc_info=True)
|
||||
# 빈 응답 반환
|
||||
return RealtimeSuggestionsResponse(suggestions=[])
|
||||
|
||||
async def generate_summary(
|
||||
self,
|
||||
text: str,
|
||||
language: str = "ko",
|
||||
style: str = "bullet",
|
||||
max_length: int = None
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
텍스트 요약 생성
|
||||
|
||||
Args:
|
||||
text: 요약할 텍스트
|
||||
language: 요약 언어 (ko/en)
|
||||
style: 요약 스타일 (bullet/paragraph)
|
||||
max_length: 최대 요약 길이
|
||||
|
||||
Returns:
|
||||
요약 결과 딕셔너리
|
||||
"""
|
||||
from app.models.summary import SummaryResponse
|
||||
from app.prompts.summary_prompt import get_summary_prompt
|
||||
|
||||
try:
|
||||
# 프롬프트 생성
|
||||
system_prompt, user_prompt = get_summary_prompt(
|
||||
text=text,
|
||||
language=language,
|
||||
style=style,
|
||||
max_length=max_length
|
||||
)
|
||||
|
||||
# Claude API 호출
|
||||
result = await self.generate_completion(
|
||||
prompt=user_prompt,
|
||||
system_prompt=system_prompt
|
||||
)
|
||||
|
||||
# 단어 수 계산
|
||||
summary_text = result.get("summary", "")
|
||||
key_points = result.get("key_points", [])
|
||||
|
||||
# 한국어와 영어의 단어 수 계산 방식 다르게 처리
|
||||
if language == "ko":
|
||||
# 한국어: 공백으로 구분된 어절 수
|
||||
original_word_count = len(text.split())
|
||||
summary_word_count = len(summary_text.split())
|
||||
else:
|
||||
# 영어: 공백으로 구분된 단어 수
|
||||
original_word_count = len(text.split())
|
||||
summary_word_count = len(summary_text.split())
|
||||
|
||||
compression_ratio = summary_word_count / original_word_count if original_word_count > 0 else 0
|
||||
|
||||
# 응답 생성
|
||||
response = SummaryResponse(
|
||||
summary=summary_text,
|
||||
key_points=key_points,
|
||||
word_count=summary_word_count,
|
||||
original_word_count=original_word_count,
|
||||
compression_ratio=round(compression_ratio, 2)
|
||||
)
|
||||
|
||||
logger.info(f"요약 생성 완료 - 원본: {original_word_count}단어, 요약: {summary_word_count}단어")
|
||||
|
||||
return response.model_dump()
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"요약 생성 실패: {e}", exc_info=True)
|
||||
raise
|
||||
|
||||
|
||||
# 싱글톤 인스턴스
|
||||
|
||||
Reference in New Issue
Block a user