From ec60261439244f9c4bd01e4bf6cfe306a9534f86 Mon Sep 17 00:00:00 2001 From: uommou Date: Mon, 27 May 2024 15:55:45 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20recommendation=20main=20=ED=8C=8C?= =?UTF-8?q?=EC=8B=B1=20=EB=B0=8F=20=ED=94=84=EB=A1=AC=ED=94=84=ED=8A=B8=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 --- app/prompt/openai_prompt.py | 2 +- app/routers/recommendation.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/prompt/openai_prompt.py b/app/prompt/openai_prompt.py index 6446246..391c148 100644 --- a/app/prompt/openai_prompt.py +++ b/app/prompt/openai_prompt.py @@ -26,7 +26,7 @@ class Template: 2. Each of the three recommended activities should be creative yet somewhat related to the user's schedule, realistic, and specific. 3. Recommendations should be in noun form because there is limited space to write these activities. 4. Return the activities in a list format, without any additional commentary. - 5. The user's schedule may not exist, and if so, do not randomly create the user's schedule and only recommend activities according to established rules. + 5. The user's schedule may not exist, and if so, do not randomly create the user's schedule and only recommend activities that helps the user. Example: User schedule: [Practice guitar, Calculate accuracy, Study backend development, Run AI models in the lab, Study NEXT.JS] diff --git a/app/routers/recommendation.py b/app/routers/recommendation.py index cb0eb20..4fb0e48 100644 --- a/app/routers/recommendation.py +++ b/app/routers/recommendation.py @@ -61,7 +61,8 @@ async def get_recommendation(user_data: RecommendationMainRequestDTO) -> Recomme # 한 줄 추천 기반 활동 추천하기 month_schedule = await vectordb.activity_recommendation_schedule(user_data, ness) print(month_schedule) - if not month_schedule: + # month_schedule이 비어있거나 [[]]인 경우 "No schedule"로 설정 + if not month_schedule or month_schedule == [[]]: month_schedule = "No schedule" print(month_schedule) @@ -73,11 +74,15 @@ async def get_recommendation(user_data: RecommendationMainRequestDTO) -> Recomme )) print(activity_response) + # AI 응답 파싱 try: + # activity_response에서 "AI Recommendation:" 부분을 제거하고, [] 사이의 텍스트만 남김 if activity_response.startswith("AI Recommendation:"): activity_response = activity_response[len("AI Recommendation:"):] - activity_response = activity_response.strip("[]") - activities = [act.strip().strip('\"') for act in activity_response.split(',')] + activity_response = activity_response.strip() + if activity_response.startswith("[") and activity_response.endswith("]"): + activity_response = activity_response[1:-1] + activities = [act.strip().strip('"') for act in activity_response.split(',')] except (SyntaxError, ValueError): print("Error parsing the response") activities = []