Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
boto3
boto3
markdownify
16 changes: 13 additions & 3 deletions src/lambda_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from markdownify import markdownify as md

from tos_summarize import tos_summarize
from tos_evaluate import tos_evaluate
Expand Down Expand Up @@ -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'))
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential division by zero error if event['body'] is an empty string (though this is checked earlier at line 21, it still passes if body is whitespace-only). While the current validation prevents empty strings, consider the edge case where original_length could be 0 after encoding.

Suggested change
original_length = len(event['body'].encode('utf-8'))
original_length = len(event['body'].encode('utf-8'))
if original_length == 0:
return {
'statusCode': 400,
'body': json.dumps({
'error': '분석할 약관이 없습니다. (body가 비어있거나 유효하지 않습니다)'
}, ensure_ascii=False)
}

Copilot uses AI. Check for mistakes.
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)
Expand Down
6 changes: 3 additions & 3 deletions src/tos_summarize.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import boto3

def tos_summarize(text_html):
def tos_summarize(tos_content):
system_instruction=[{"text": """
당신은 약관 분석 전문가입니다.
주어진 html 페이지에서 주요 약관 내용을 요약합니다.
주어진 텍스트에서 주요 약관 내용을 요약합니다.
한국어로 응답합니다.
"""}]

Expand All @@ -16,7 +16,7 @@ def tos_summarize(text_html):
messages = [{
"role": "user",
"content": [
{"text": text_html}
{"text": tos_content}
]
}]

Expand Down