diff --git a/requirements.txt b/requirements.txt index 1db657b..8f97f3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -boto3 \ No newline at end of file +boto3 +markdownify \ No newline at end of file diff --git a/src/lambda_function.py b/src/lambda_function.py index d8a3955..bbaec90 100644 --- a/src/lambda_function.py +++ b/src/lambda_function.py @@ -1,4 +1,5 @@ import json +from markdownify import markdownify as md from tos_summarize import tos_summarize from tos_evaluate import tos_evaluate @@ -26,12 +27,21 @@ def lambda_handler(event, context): } url = event['queryStringParameters']['url'] - text_html = event['body'] + tos_content = md(event['body']) + + # 바이트 기준으로 길이 및 감소율 계산 + original_length = len(event['body'].encode('utf-8')) + markdown_length = len(tos_content.encode('utf-8')) + reduction = (original_length - markdown_length) / original_length * 100 + + print(f"원본 html 길이: {original_length} bytes") + print(f"markdown 길이: {markdown_length} bytes") + print(f"감소율: {reduction:.2f}%") # TODO: 기존 URL 기반 캐싱 로직 구현 - # text_html 문자열에서 중요 조항 위주로 약관 요약 - summarized_tos = tos_summarize(text_html) + # tos_content 문자열에서 중요 조항 위주로 약관 요약 + summarized_tos = tos_summarize(tos_content) # 약관 조항에 대해 분석 수행 evaluation_result = tos_evaluate(summarized_tos) diff --git a/src/tos_summarize.py b/src/tos_summarize.py index 892bed2..8263f67 100644 --- a/src/tos_summarize.py +++ b/src/tos_summarize.py @@ -1,9 +1,9 @@ import boto3 -def tos_summarize(text_html): +def tos_summarize(tos_content): system_instruction=[{"text": """ 당신은 약관 분석 전문가입니다. -주어진 html 페이지에서 주요 약관 내용을 요약합니다. +주어진 텍스트에서 주요 약관 내용을 요약합니다. 한국어로 응답합니다. """}] @@ -16,7 +16,7 @@ def tos_summarize(text_html): messages = [{ "role": "user", "content": [ - {"text": text_html} + {"text": tos_content} ] }]