Skip to content

Commit

Permalink
fix: recommendation main 파싱 및 프롬프트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
uommou committed May 27, 2024
1 parent 7b1f144 commit ec60261
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/prompt/openai_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 8 additions & 3 deletions app/routers/recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 = []
Expand Down

0 comments on commit ec60261

Please sign in to comment.