From 7645030774612d3ce561c71c1771a752f1aa5234 Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Tue, 11 Nov 2025 23:44:50 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20Gemini=20API=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=82=B4=EC=9A=A9=20=EC=A0=9C=EA=B1=B0=20AWS=20Bed?= =?UTF-8?q?rock=EC=97=90=EC=84=9C=20=EC=A7=80=EC=9B=90=ED=95=98=EB=8A=94?= =?UTF-8?q?=20Claude=20API=EB=A1=9C=20=EC=9D=B4=EC=A0=84=ED=95=98=EA=B8=B0?= =?UTF-8?q?=20=EC=9C=84=ED=95=A8=EC=9E=85=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 -- requirements.txt | 1 - src/lambda_function.py | 10 ++-------- src/test_local.py | 8 -------- src/tos_evaluate.py | 42 +----------------------------------------- src/tos_summarize.py | 15 +-------------- 6 files changed, 4 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 79ae96c..d2aed78 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ # 아키텍처 AWS Lambda -Gemini # Getting Started ## 개발환경 구축 @@ -13,7 +12,6 @@ bash를 기준으로 작성됨 sudo apt install python3.12-venv python3 -m venv venv # 가상환경 생성 source venv/bin/activate # 가상환경 사용 -pip install -q -U google-genai ``` 이후부터 작업 시 `source venv/bin/activate` 명령으로 가상환경을 실행한 후 작업 diff --git a/requirements.txt b/requirements.txt index 4175144..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +0,0 @@ -google-genai \ No newline at end of file diff --git a/src/lambda_function.py b/src/lambda_function.py index 9f1009b..f885918 100644 --- a/src/lambda_function.py +++ b/src/lambda_function.py @@ -1,14 +1,9 @@ import json -import os -from google import genai from tos_summarize import tos_summarize from tos_evaluate import tos_evaluate def lambda_handler(event, context): - GEMINI_API_KEY = os.getenv('GEMINI_API_KEY') - client = genai.Client(api_key=GEMINI_API_KEY) - # url이 없거나 빈 문자열인 경우 if ('queryStringParameters' not in event or 'url' not in event['queryStringParameters'] @@ -36,11 +31,10 @@ def lambda_handler(event, context): # TODO: 기존 URL 기반 캐싱 로직 구현 # text_html 문자열에서 중요 조항 위주로 약관 요약 - summarized_tos = tos_summarize(text_html, client) + summarized_tos = None # 약관 조항에 대해 분석 수행 - # gemini api의 rate limit 문제로, 여러 조항을 한 번에 보내지 않고 하나씩 처리 - evaluation_result = tos_evaluate(summarized_tos, client) + evaluation_result = None return { 'statusCode': 200, diff --git a/src/test_local.py b/src/test_local.py index 75abe22..d00417e 100644 --- a/src/test_local.py +++ b/src/test_local.py @@ -1,4 +1,3 @@ -import os from lambda_function import lambda_handler @@ -15,13 +14,6 @@ def create_test_event(url: str, body: str) -> dict: def run_test(): """Lambda 함수 로컬 테스트 실행""" - # GEMINI_API_KEY 확인 - api_key = os.getenv('GEMINI_API_KEY') - if not api_key: - print("GEMINI_API_KEY 환경변수가 설정되지 않았습니다.") - print() - return - # 테스트 데이터 test_url = "https://example.com/terms" test_body = """ diff --git a/src/tos_evaluate.py b/src/tos_evaluate.py index 64f23cd..e15d8a2 100644 --- a/src/tos_evaluate.py +++ b/src/tos_evaluate.py @@ -1,47 +1,7 @@ -import enum import json -from google import genai -from google.genai import types def tos_evaluate(summarized_tos, client): - response = client.models.generate_content( - model="gemini-2.5-flash-lite", - config=types.GenerateContentConfig( - system_instruction= - """ - 당신은 약관 분석 전문가입니다. 주어진 약관 및 각 조항을 평가합니다. - 각 약관 조항은 good, neutral, bad 중 하나로 평가합니다. - 'good'은 이용자에게 유리한 조항, 'neutral'은 중립적인 조항, 'bad'는 이용자에게 불리한 조항을 의미합니다. - A, B, C, D, E 등급 중 하나로 전체 약관을 평가합니다. - A는 매우 우수한 약관, E는 매우 불리한 약관을 의미합니다. - 한국어로 응답합니다. - """, - response_mime_type="application/json", - response_schema={ - "type": "object", - "properties": { - "overall_evaluation": { - "type": "string" - }, - "evaluation_for_each_clause": { - "type": "array", - "items": { - "type": "object", - "properties": { - "evaluation": { - "type": "string" - }, - "summarized_clause": { - "type": "string" - } - } - } - } - } - } - ), - contents=summarized_tos, - ) + response = None # response에서 JSON 파싱 후 반환 diff --git a/src/tos_summarize.py b/src/tos_summarize.py index 41086a5..f3f419e 100644 --- a/src/tos_summarize.py +++ b/src/tos_summarize.py @@ -1,18 +1,5 @@ -import json -from google import genai -from google.genai import types def tos_summarize(text_html, client): - response = client.models.generate_content( - model="gemini-2.5-flash-lite", - config=types.GenerateContentConfig( - system_instruction=""" - 당신은 약관 분석 전문가입니다. - 주어진 html 페이지에서 주요 약관 내용을 요약합니다. - 한국어로 응답합니다. - """, - ), - contents=text_html, - ) + response = None return response.text From c2dbe2518313b0b2b10daed17f3085b8eb2493a1 Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Wed, 12 Nov 2025 13:10:42 +0900 Subject: [PATCH 02/10] =?UTF-8?q?chore:=20bedrock=20=ED=98=B8=EC=B6=9C?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20boto3=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index e69de29..1db657b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +boto3 \ No newline at end of file From 5271432e611eac93cd41e536778f547686b4749d Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Wed, 12 Nov 2025 13:11:36 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20bedrock=EC=9D=98=20claude=203.5?= =?UTF-8?q?=20haiku=20=EB=AA=A8=EB=8D=B8=EC=9D=84=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=95=BD=EA=B4=80=20=EC=9A=94=EC=95=BD?= =?UTF-8?q?=EC=9D=84=20=EC=A0=9C=EA=B3=B5=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tos_summarize.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/tos_summarize.py b/src/tos_summarize.py index f3f419e..10e8957 100644 --- a/src/tos_summarize.py +++ b/src/tos_summarize.py @@ -1,5 +1,35 @@ +import boto3 -def tos_summarize(text_html, client): - response = None +def tos_summarize(text_html): + # Create the Bedrock client + client = boto3.client( + service_name="bedrock-runtime", + region_name="us-west-2" + ) - return response.text + # Define the model and message + model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0" + messages = [ + { + "role": "user", + "content": [ + {"text": text_html} + ] + } + ] + + # Make the API call + response = client.converse( + modelId=model_id, + system=""" +당신은 약관 분석 전문가입니다. +주어진 html 페이지에서 주요 약관 내용을 요약합니다. +한국어로 응답합니다. +""", + messages=messages, + ) + + print("TOS Summarization Response:") + print(response) + + return response['output']['message']['content'][0]['text'] From d93a95683aa7d9404e7d3c2c41e4af92c81e22d5 Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Wed, 12 Nov 2025 13:11:45 +0900 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20bedrock=EC=9D=98=20claude=203.5?= =?UTF-8?q?=20haiku=20=EB=AA=A8=EB=8D=B8=EC=9D=84=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=95=BD=EA=B4=80=20=EC=A1=B0=ED=95=AD=20?= =?UTF-8?q?=ED=8F=89=EA=B0=80=EB=A5=BC=20=EC=A0=9C=EA=B3=B5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tos_evaluate.py | 55 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/src/tos_evaluate.py b/src/tos_evaluate.py index e15d8a2..17181b6 100644 --- a/src/tos_evaluate.py +++ b/src/tos_evaluate.py @@ -1,8 +1,55 @@ import json +import boto3 -def tos_evaluate(summarized_tos, client): - response = None +def tos_evaluate(summarized_tos): + client = boto3.client( + service_name="bedrock-runtime", + region_name="us-west-2" +) - # response에서 JSON 파싱 후 반환 + model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0" + messages = [{ + "role": "user", + "content": [{"text": summarized_tos}] + }] + + response = client.converse( + modelId=model_id, + system=""" +당신은 약관 분석 전문가입니다. 주어진 약관 및 각 조항을 평가합니다. +각 약관 조항은 good, neutral, bad 중 하나로 평가합니다. +'good'은 이용자에게 유리한 조항, 'neutral'은 중립적인 조항, 'bad'는 이용자에게 불리한 조항을 의미합니다. +A, B, C, D, E 등급 중 하나로 전체 약관을 평가합니다. +A는 매우 우수한 약관, E는 매우 불리한 약관을 의미합니다. +한국어로 응답합니다. +아래의 JSON 양식으로 응답합니다: +{ + "overall_evaluation": "D", + "evaluation_for_each_clause": [ + { + "evaluation": "neutral", + "summarized_clause": "AWS 사이트 콘텐츠의 저작권은 AWS 또는 제공자에게 있으며, 관련 법률에 의해 보호됨을 명시합니다." + }, + { + "evaluation": "neutral", + "summarized_clause": "AWS 상표 및 트레이드 드레스는 허가 없이 사용할 수 없으며, 타사 상표는 해당 소유자에게 있음을 명시합니다." + }, + { + "evaluation": "bad", + "summarized_clause": "개인적인 사이트 이용 목적 외 상업적 재판매, 복제, 변경 등은 사전 서면 동의 없이는 금지됨을 명시하며, 이는 일반적인 내용이나 명확한 제한을 둠." + }, + { + "evaluation": "bad", + "summarized_clause": "이용자의 계정 및 비밀번호 관리 책임을 명시하고, 계정 활동에 대한 책임을 이용자에게 부과합니다. 또한 AWS는 일방적으로 서비스 거절 및 계정 해지 권한을 가집니다." + } + ] +} +""", + messages=messages, + ) - return json.loads(response.text) + print("TOS Evaluation Response:") + print(response) + + # response에서 JSON 파싱 후 반환 + return json.loads(response['output']['message']['content'][0]['text']) From c869bb03cdf2f02ad204bb077320da5eb8c2e1f6 Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Wed, 12 Nov 2025 13:12:10 +0900 Subject: [PATCH 05/10] =?UTF-8?q?fix:=20=EC=88=98=EC=A0=95=EB=90=9C=20tos?= =?UTF-8?q?=5Fsummarize=EC=99=80=20tos=5Fevaluate=EB=A5=BC=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lambda_function.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lambda_function.py b/src/lambda_function.py index f885918..d8a3955 100644 --- a/src/lambda_function.py +++ b/src/lambda_function.py @@ -31,10 +31,10 @@ def lambda_handler(event, context): # TODO: 기존 URL 기반 캐싱 로직 구현 # text_html 문자열에서 중요 조항 위주로 약관 요약 - summarized_tos = None + summarized_tos = tos_summarize(text_html) # 약관 조항에 대해 분석 수행 - evaluation_result = None + evaluation_result = tos_evaluate(summarized_tos) return { 'statusCode': 200, From 5daec2e948d306e4b0255486a424f2862e5734a5 Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Wed, 12 Nov 2025 15:48:48 +0900 Subject: [PATCH 06/10] =?UTF-8?q?fix:=20tos=5Fsummarize=EC=99=80=20tos=5Fe?= =?UTF-8?q?valuate=EC=97=90=EC=84=9C=20system=20instruction=EC=9D=84=20?= =?UTF-8?q?=EC=98=AC=EB=B0=94=EB=A5=B4=EA=B2=8C=20=EC=A0=84=EB=8B=AC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tos_evaluate.py | 33 ++++++++++++++++++--------------- src/tos_summarize.py | 29 +++++++++++++---------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/tos_evaluate.py b/src/tos_evaluate.py index 17181b6..4f5a1d6 100644 --- a/src/tos_evaluate.py +++ b/src/tos_evaluate.py @@ -2,20 +2,7 @@ import boto3 def tos_evaluate(summarized_tos): - client = boto3.client( - service_name="bedrock-runtime", - region_name="us-west-2" -) - - model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0" - messages = [{ - "role": "user", - "content": [{"text": summarized_tos}] - }] - - response = client.converse( - modelId=model_id, - system=""" + system_instruction=[{"text": """ 당신은 약관 분석 전문가입니다. 주어진 약관 및 각 조항을 평가합니다. 각 약관 조항은 good, neutral, bad 중 하나로 평가합니다. 'good'은 이용자에게 유리한 조항, 'neutral'은 중립적인 조항, 'bad'는 이용자에게 불리한 조항을 의미합니다. @@ -44,7 +31,23 @@ def tos_evaluate(summarized_tos): } ] } -""", +"""}] + client = boto3.client( + service_name="bedrock-runtime", + region_name="us-west-2" +) + + model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0" + messages = [{ + "role": "user", + "content": [ + {"text": summarized_tos} + ] + }] + + response = client.converse( + modelId=model_id, + system=system_instruction, messages=messages, ) diff --git a/src/tos_summarize.py b/src/tos_summarize.py index 10e8957..7dd73b6 100644 --- a/src/tos_summarize.py +++ b/src/tos_summarize.py @@ -1,31 +1,28 @@ import boto3 def tos_summarize(text_html): - # Create the Bedrock client + system_instruction=[{"text": """ +당신은 약관 분석 전문가입니다. +주어진 html 페이지에서 주요 약관 내용을 요약합니다. +한국어로 응답합니다. +"""}] + client = boto3.client( service_name="bedrock-runtime", region_name="us-west-2" ) - # Define the model and message model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0" - messages = [ - { - "role": "user", - "content": [ - {"text": text_html} - ] - } - ] + messages = [{ + "role": "user", + "content": [ + {"text": text_html} + ] + }] - # Make the API call response = client.converse( modelId=model_id, - system=""" -당신은 약관 분석 전문가입니다. -주어진 html 페이지에서 주요 약관 내용을 요약합니다. -한국어로 응답합니다. -""", + system=system_instruction, messages=messages, ) From 8873ce0c4f84a38e873c9266bb7a17a5a9aa9a9b Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Wed, 12 Nov 2025 16:12:28 +0900 Subject: [PATCH 07/10] =?UTF-8?q?fix:=20claude=EA=B0=80=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=84=9C=EB=A1=A0/=EA=B2=B0?= =?UTF-8?q?=EB=A1=A0=20=EB=93=B1=EC=9D=84=20=EB=A7=90=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EB=AA=BB=ED=95=98=EB=8F=84=EB=A1=9D=20=ED=98=95=EC=8B=9D?= =?UTF-8?q?=EC=9D=84=20=EA=B5=AC=EC=B2=B4=EC=A0=81=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20structured=20output=EC=9D=B4=20=EC=A7=80?= =?UTF-8?q?=EC=9B=90=EB=90=98=EC=A7=80=20=EC=95=8A=EC=8A=B5=EB=8B=88?= =?UTF-8?q?=EB=8B=A4...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tos_evaluate.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/tos_evaluate.py b/src/tos_evaluate.py index 4f5a1d6..1b3f8e5 100644 --- a/src/tos_evaluate.py +++ b/src/tos_evaluate.py @@ -3,13 +3,20 @@ def tos_evaluate(summarized_tos): system_instruction=[{"text": """ -당신은 약관 분석 전문가입니다. 주어진 약관 및 각 조항을 평가합니다. -각 약관 조항은 good, neutral, bad 중 하나로 평가합니다. -'good'은 이용자에게 유리한 조항, 'neutral'은 중립적인 조항, 'bad'는 이용자에게 불리한 조항을 의미합니다. -A, B, C, D, E 등급 중 하나로 전체 약관을 평가합니다. -A는 매우 우수한 약관, E는 매우 불리한 약관을 의미합니다. -한국어로 응답합니다. -아래의 JSON 양식으로 응답합니다: +당신은 전문적인 약관 분석 AI입니다. 주어진 약관 내용 및 각 조항을 평가합니다. +주어진 약관은 주요 조항을 위주로 요약된 내용입니다. +JSON 양식으로, 그리고 어떠한 서론이나 결론 따위 없이 JSON 양식만으로 응답합니다. 다음의 key값을 사용합니다. +"overall_evaluation": "A|B|C|D|E", +"evaluation_for_each_clause": [ + "evaluation": "good|neutral|bad", + "summarized_clause": "조항 요약 내용" +] +"overall_evaluation"은 전체 약관의 등급을 나타냅니다. A는 가장 우수한 약관, E는 가장 불리한 약관입니다. +"evaluation_for_each_clause"는 각 조항에 대한 평가를 포함하는 리스트입니다. +"evaluation"은 각 조항이 소비자에게 유리한지(good)/중립적인지(neutral)/불리한지(bad)를 나타냅니다. +"summarized_clause"는 각 조항의 요약된 내용을 포함합니다. + +예시 응답: { "overall_evaluation": "D", "evaluation_for_each_clause": [ From 3f4c58b5247ff2930cad766ae03f77e6946f9db6 Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Wed, 12 Nov 2025 16:29:15 +0900 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20claude=20=EB=AA=A8=EB=8D=B8?= =?UTF-8?q?=EC=9D=84=203.5=20haiku=EC=97=90=EC=84=9C=20sonnet=204.5?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tos_evaluate.py | 2 +- src/tos_summarize.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tos_evaluate.py b/src/tos_evaluate.py index 1b3f8e5..761ebc9 100644 --- a/src/tos_evaluate.py +++ b/src/tos_evaluate.py @@ -44,7 +44,7 @@ def tos_evaluate(summarized_tos): region_name="us-west-2" ) - model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0" + model_id = "us.anthropic.claude-sonnet-4-5-20250929-v1:0" messages = [{ "role": "user", "content": [ diff --git a/src/tos_summarize.py b/src/tos_summarize.py index 7dd73b6..892bed2 100644 --- a/src/tos_summarize.py +++ b/src/tos_summarize.py @@ -12,7 +12,7 @@ def tos_summarize(text_html): region_name="us-west-2" ) - model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0" + model_id = "us.anthropic.claude-sonnet-4-5-20250929-v1:0" messages = [{ "role": "user", "content": [ From 0da493843f442d3cc1d755132eab4bd76a735bf8 Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Wed, 12 Nov 2025 18:05:34 +0900 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20claude=EA=B0=80=20=EC=96=91?= =?UTF-8?q?=EC=8B=9D=EC=9D=84=20=EB=8D=94=20=EC=9E=98=20=EC=A7=80=ED=82=A4?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=ED=94=84=EB=A1=AC=ED=94=84=ED=8A=B8=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0=20=EC=97=AC=EB=8A=94=20=EC=A4=91=EA=B4=84?= =?UTF-8?q?=ED=98=B8=EB=A1=9C=20=EC=9D=91=EB=8B=B5=EC=9D=84=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91=ED=95=98=EA=B3=A0=20=EB=8B=AB=EB=8A=94=20=EC=A4=91?= =?UTF-8?q?=EA=B4=84=ED=98=B8=EB=A1=9C=20=EC=9D=91=EB=8B=B5=EC=9D=84=20?= =?UTF-8?q?=EB=81=9D=EB=A7=88=EC=B9=98=EB=8F=84=EB=A1=9D=20=EC=A7=80?= =?UTF-8?q?=EC=8B=9C=ED=95=A9=EB=8B=88=EB=8B=A4.=20=EC=9D=B4=20=EB=B0=A9?= =?UTF-8?q?=EB=B2=95=EB=A7=88=EC=A0=80=20=EC=86=8C=EC=9A=A9=EC=9D=B4=20?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EA=B2=BD=EC=9A=B0,=20=EC=A4=91=EA=B4=84?= =?UTF-8?q?=ED=98=B8=EB=A5=BC=20=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=AC=B8=EC=9E=90=EC=97=B4=EC=9D=84=20=EC=9E=98=EB=9D=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8A=94=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=EC=9D=84=20=EC=A0=81=EC=9A=A9=ED=95=A9=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tos_evaluate.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tos_evaluate.py b/src/tos_evaluate.py index 761ebc9..e044f74 100644 --- a/src/tos_evaluate.py +++ b/src/tos_evaluate.py @@ -5,7 +5,7 @@ def tos_evaluate(summarized_tos): system_instruction=[{"text": """ 당신은 전문적인 약관 분석 AI입니다. 주어진 약관 내용 및 각 조항을 평가합니다. 주어진 약관은 주요 조항을 위주로 요약된 내용입니다. -JSON 양식으로, 그리고 어떠한 서론이나 결론 따위 없이 JSON 양식만으로 응답합니다. 다음의 key값을 사용합니다. +JSON 양식으로, 다음의 key값을 사용합니다. "overall_evaluation": "A|B|C|D|E", "evaluation_for_each_clause": [ "evaluation": "good|neutral|bad", @@ -15,7 +15,8 @@ def tos_evaluate(summarized_tos): "evaluation_for_each_clause"는 각 조항에 대한 평가를 포함하는 리스트입니다. "evaluation"은 각 조항이 소비자에게 유리한지(good)/중립적인지(neutral)/불리한지(bad)를 나타냅니다. "summarized_clause"는 각 조항의 요약된 내용을 포함합니다. - +JSON 형식 이외에 서론이나 결론, 코드 블럭 따위는 절대로 포함하지 마십시오. +응답은 곧바로 json.loads()를 통해 파싱되기 때문에 반드시 여는 중괄호(`{`})로 시작하고 닫는 중괄호(`}`)로 끝나야 합니다. 예시 응답: { "overall_evaluation": "D", From 2d96096dfe1096159215b25c1e46e8cd2d81cc81 Mon Sep 17 00:00:00 2001 From: Hyeongjun Ham Date: Wed, 12 Nov 2025 22:30:18 +0900 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20claude=EC=9D=98=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EC=9D=84=20=EC=97=AC=EB=8A=94=20=EC=A4=91=EA=B4=84?= =?UTF-8?q?=ED=98=B8=EB=B6=80=ED=84=B0=20=EB=8B=AB=EB=8A=94=20=EC=A4=91?= =?UTF-8?q?=EA=B4=84=ED=98=B8=EA=B9=8C=EC=A7=80=20=EC=9E=98=EB=9D=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=20Claude=20=EB=AA=A8=EB=8D=B8=EC=9D=98=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=EC=9D=B4=20=EB=AA=85=EC=8B=9C=ED=95=9C=20?= =?UTF-8?q?=EC=96=91=EC=8B=9D=EC=9E=84=EC=9D=84=20=EC=8B=A0=EB=A2=B0?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=97=86=EC=9C=BC=EB=AF=80=EB=A1=9C,?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=EC=97=90=20=ED=8F=AC=ED=95=A8=EB=90=9C=20?= =?UTF-8?q?=EC=B2=98=EC=9D=8C=20=EC=97=AC=EB=8A=94=20=EC=A4=91=EA=B4=84?= =?UTF-8?q?=ED=98=B8=EB=B6=80=ED=84=B0=20=EB=A7=88=EC=A7=80=EB=A7=89=20?= =?UTF-8?q?=EB=8B=AB=EB=8A=94=20=EC=A4=91=EA=B4=84=ED=98=B8=EA=B9=8C?= =?UTF-8?q?=EC=A7=80=20=EC=9E=98=EB=9D=BC=EB=82=B4=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=A9=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tos_evaluate.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tos_evaluate.py b/src/tos_evaluate.py index e044f74..054eb2f 100644 --- a/src/tos_evaluate.py +++ b/src/tos_evaluate.py @@ -62,5 +62,10 @@ def tos_evaluate(summarized_tos): print("TOS Evaluation Response:") print(response) + text = response['output']['message']['content'][0]['text'] + start = text.find('{') + end = text.rfind('}') + 1 + json_text = text[start:end] + # response에서 JSON 파싱 후 반환 - return json.loads(response['output']['message']['content'][0]['text']) + return json.loads(json_text) \ No newline at end of file