Skip to content

Commit

Permalink
Merge pull request #46 from studio-recoding/fix/tags
Browse files Browse the repository at this point in the history
[fix] 태그 리턴에 description 추가
  • Loading branch information
uommou authored Apr 12, 2024
2 parents 1d2d649 + c2acb68 commit 0855210
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
8 changes: 6 additions & 2 deletions app/dto/openai_dto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pydantic import BaseModel

from typing import List

class PromptRequest(BaseModel):
prompt: str
Expand All @@ -11,5 +11,9 @@ class ChatCaseResponse(BaseModel):
ness: str
case: int

class TagDescription(BaseModel):
tag: str
desc: str

class TagsResponse(BaseModel):
tags: list
tagList: List[TagDescription]
2 changes: 1 addition & 1 deletion app/prompt/openai_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ MAX_TOKENS = 2048
MODEL_NAME = gpt-4

[NESS_TAGS]
TEMPERATURE = 0
TEMPERATURE = 0.5
MAX_TOKENS = 2048
MODEL_NAME = gpt-4
33 changes: 17 additions & 16 deletions app/prompt/report_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ class Template:
"""

report_tags_template = """
You are an AI assistant tasked with analyzing a user's schedule over the span of a month. From this detailed schedule, you will distill three keywords that best encapsulate the user's activities, interests, or achievements throughout the month. These keywords should not only reflect the user's endeavors but also convey a sense of accomplishment and enjoyment. Your output should be engaging, showcasing your wit and unique perspective. Here are the rules for your analysis:
YOU MUST USE {output_language} TO RESPOND TO THE INPUT.
YOU MUST PROVIDE THREE KEYWORDS in your response. Each keyword should be a single word or a concise phrase.
The keywords must capture the essence of the user's monthly activities, highlighting aspects that are both rewarding and enjoyable.
Your selections should be creative and personalized, aiming to reflect the user's unique experiences over the month.
Example:
User's monthly schedule: [Attended a programming bootcamp, Completed a marathon, Read three novels, Volunteered at the local food bank, Started a blog about sustainability]
AI Recommendation: "공부 매니아, 환경 지킴이, 자기 계발 홀릭"
User's monthly schedule: [Took photography classes, Explored three new hiking trails, Organized a neighborhood clean-up, Experimented with vegan recipes]
AI Recommendation: "모험가, 미식가, 도파민 중독자"
User's monthly schedule: {schedule}
AI Recommendation:
"""
You are an AI assistant tasked with analyzing a user's schedule over the span of a month. From this detailed schedule, you will distill three keywords that best encapsulate the user's activities, interests, or achievements throughout the month. Additionally, you will provide a brief explanation for each keyword to illustrate why it was chosen, making the output more informative and engaging. Here are the rules for your analysis:
YOU MUST USE {output_language} TO RESPOND TO THE INPUT.
YOU MUST PROVIDE THREE KEYWORDS in your response, each accompanied by a concise explanation.
The keywords must capture the essence of the user's monthly activities, highlighting aspects that are both rewarding and enjoyable.
Your selections should be creative and personalized, aiming to reflect the user's unique experiences over the month.
Each explanation of the keywords must not exceed 50 characters in the {output_language}.
Example:
User's monthly schedule: [Attended a programming bootcamp, Completed a marathon, Read three novels, Volunteered at the local food bank, Started a blog about sustainability]
AI Recommendation: "공부 매니아: 이번 달엔 공부를 정말 많이 하셨군요!, 환경 지킴이: 지속 가능한 생활에 대한 열정이 느껴져요., 자기 계발 홀릭: 성장을 위해 노력하는 모습이 멋져요."
User's monthly schedule: [Took photography classes, Explored three new hiking trails, Organized a neighborhood clean-up, Experimented with vegan recipes]
AI Recommendation: "모험가: 새로운 활동에 많이 도전하셨네요!, 미식가: 레시피 실험을 했다니 멋져요., 도파민 중독자: 즐거운 일을 많이 만드시네요!"
User's monthly schedule: {schedule}
AI Recommendation:
"""
17 changes: 12 additions & 5 deletions app/routers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from langchain_core.prompts import PromptTemplate

from app.dto.db_dto import ReportMemoryEmojiRequestDTO, ReportTagsRequestDTO
from app.dto.openai_dto import ChatResponse, TagsResponse
from app.dto.openai_dto import ChatResponse, TagsResponse, TagDescription
from app.prompt import report_prompt
import app.database.chroma_db as vectordb

Expand Down Expand Up @@ -76,10 +76,17 @@ async def get_tags(user_data: ReportTagsRequestDTO) -> TagsResponse:
prompt = PromptTemplate.from_template(report_tags_template)
result = chat_model.predict(prompt.format(output_language="Korean", schedule=schedule))
print(result)
tags = result.split("\"")[1].split(",")
tags = [tag.strip() for tag in tags]
print(tags)
return TagsResponse(tags=tags)

# 문자열 파싱해서 dto로 매핑
tag_entries = result.split("\"")[1].split(", ")
tags = []

for entry in tag_entries:
# ':'를 기준으로 태그와 설명을 분리
tag, desc = entry.split(": ")
tags.append(TagDescription(tag=tag.strip(), desc=desc.strip()))

return TagsResponse(tagList=tags)

except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

0 comments on commit 0855210

Please sign in to comment.