Skip to content

Commit

Permalink
Merge pull request #80 from studio-recoding/refactor/delete
Browse files Browse the repository at this point in the history
fix: delete 시간 형식 수정
  • Loading branch information
uommou authored Jul 16, 2024
2 parents 86e5ad0 + 983215d commit cf80d43
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 68 deletions.
104 changes: 49 additions & 55 deletions app/prompt/openai_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,59 +187,53 @@ class Template:
{persona}
{chat_type}
The user's input contains information about several events they want to delete in their schedule. You have two tasks to perform:
1. Respond kindly to the user's input. YOU MUST USE {output_language} TO RESPOND TO THE USER INPUT.
2. You will be given a list of potential candidates from the database for events that the user may want to delete, and you must organize those events that the user has indicated they want to delete into a list. Organize the events the user wants to delete into a json format to make a delete api call in a database. Each event should be represented as a separate json object within a list. Each json object will have keys for info, location, person, start_time, end_time, and category. The category should include the name, id, and color.
- id: Find the id of the schedule in the 'ids'.
- info: The document data of the schedule.
- location: Include the venue or place where the event was scheduled to occur.
- person: List any specific individuals involved in the event.
- start_time: The scheduled start time of the event in ISO 8601 datetime format.
- end_time: The scheduled end time of the event in ISO 8601 datetime format.
- category: The event category with name, id, and an optional color.
Separate the outputs for tasks 1 and 2 with a special token <separate>. Even if there is only one JSON object, it must be enclosed within a list.
Example for one-shot learning:
User input: 개발 공부하기와 한강에서의 놀러가기 이벤트를 삭제해 주세요.
Schedules: {{'ids': [['29', '8', '7', '25', '16']], 'distances': [[0.1681539537965312, 0.17174183647570107, 0.2014914961195574, 0.2014914961195574, 0.21989337760155114]], 'embeddings': None, 'metadatas': [[{{'category': '🍀미분류', 'category_id': 29, 'date': 27, 'datetime_end': '2024-05-27T16:00:00Z', 'datetime_start': '2024-05-27T15:00:00Z', 'location': '공대', 'member': 1, 'month': 5, 'person': '', 'year': 2024}}, {{'category': '공부', 'category_id': 8, 'date': 25, 'datetime_end': '2024-05-25T16:00:00Z', 'datetime_start': '2024-05-25T15:00:00Z', 'location': '카페', 'member': 1, 'month': 5, 'person': '민주, 채원', 'year': 2024}}, {{'category': '공부', 'category_id': 7, 'date': 10, 'datetime_end': '2024-05-10T00:00:00Z', 'datetime_start': '2024-05-10T00:00:00Z', 'location': '한강', 'member': 1, 'month': 5, 'person': '혜승', 'year': 2024}}, {{'category': '🍀미분류', 'category_id': 25, 'date': 10, 'datetime_end': '2024-05-10T00:00:00Z', 'datetime_start': '2024-05-10T00:00:00Z', 'location': '한강', 'member': 1, 'month': 5, 'person': '혜승', 'year': 2024}}, {{'category': '📖 공부', 'category_id': 16, 'date': 15, 'datetime_end': '2024-05-15T16:00:00Z', 'datetime_start': '2024-05-15T15:00:00Z', 'location': '', 'member': 3, 'month': 5, 'person': '', 'year': 2024}}]], 'documents': [['개발 공부하기', '열심히 개발하기', '한강 놀러가기', '한강 놀러가기', '리액트 공부하기']], 'uris': None, 'data': None}}
Response to user: 다음의 일정을 삭제해드릴까요?
<separate>
[
{{
"id": 29
"info": "개발 공부하기",
"location": "공대",
"person": "",
"start_time": "2024-05-27T15:00:00Z",
"end_time": "2024-05-27T16:00:00Z",
"category": {{
"name": "🍀미분류",
"id": 29,
"color": ""
}}
}},
{{
"id": 7
"info": "한강 놀러가기",
"location": "한강",
"person": "혜승",
"start_time": "2024-05-10T00:00:00Z",
"end_time": "2024-05-10T00:00:00Z",
"category": {{
"name": "🍀미분류",
"id": 25,
"color": ""
}}
}}
]
User input: {question}
Schedules: {schedule}
Response to user:
1. Respond kindly to the user's input. YOU MUST USE {output_language} TO RESPOND TO THE USER INPUT.
2. You will be given a list of potential candidates from the database for events that the user may want to delete, and you must organize those events that the user has indicated they want to delete into a list. Organize the events the user wants to delete into a json format to make a delete api call in a database. Each event should be represented as a separate json object within a list. Each json object will have keys for info, location, person, start_time, end_time, and category. The category should include the name, id, and color.
- id: Find the id of the schedule in the 'ids'.
- info: The document data of the schedule.
- location: Include the venue or place where the event was scheduled to occur.
- person: List any specific individuals involved in the event.
- start_time: The scheduled start time of the event in ISO 8601 datetime format with timezone.
- end_time: The scheduled end time of the event in ISO 8601 datetime format with timezone.
- category: The event category with name, id, and an optional color.
Separate the outputs for tasks 1 and 2 with a special token <separate>. Even if there is only one JSON object, it must be enclosed within a list.
Example for one-shot learning:
User input: 개발 공부하기와 한강에서의 놀러가기 이벤트를 삭제해 주세요.
Schedules: {{'ids': [['29', '8', '7', '25', '16']], 'distances': [[0.1681539537965312, 0.17174183647570107, 0.2014914961195574, 0.2014914961195574, 0.21989337760155114]], 'embeddings': None, 'metadatas': [[{{'category': '🍀미분류', 'category_id': 29, 'date': 27, 'datetime_end': '2024-05-27T16:00:00+09:00', 'datetime_start': '2024-05-27T15:00:00+09:00', 'location': '공대', 'member': 1, 'month': 5, 'person': '', 'year': 2024}}, {{'category': '공부', 'category_id': 8, 'date': 25, 'datetime_end': '2024-05-25T16:00:00+09:00', 'datetime_start': '2024-05-25T15:00:00+09:00', 'location': '카페', 'member': 1, 'month': 5, 'person': '민주, 채원', 'year': 2024}}, {{'category': '공부', 'category_id': 7, 'date': 10, 'datetime_end': '2024-05-10T00:00:00+09:00', 'datetime_start': '2024-05-10T00:00:00+09:00', 'location': '한강', 'member': 1, 'month': 5, 'person': '혜승', 'year': 2024}}, {{'category': '🍀미분류', 'category_id': 25, 'date': 10, 'datetime_end': '2024-05-10T00:00:00+09:00', 'datetime_start': '2024-05-10T00:00:00+09:00', 'location': '한강', 'member': 1, 'month': 5, 'person': '혜승', 'year': 2024}}, {{'category': '📖 공부', 'category_id': 16, 'date': 15, 'datetime_end': '2024-05-15T16:00:00+09:00', 'datetime_start': '2024-05-15T15:00:00+09:00', 'location': '', 'member': 3, 'month': 5, 'person': '', 'year': 2024}}]], 'documents': [['개발 공부하기', '열심히 개발하기', '한강 놀러가기', '한강 놀러가기', '리액트 공부하기']], 'uris': None, 'data': None}}
Response to user: 다음의 일정을 삭제해드릴까요?
<separate>
[
{{
"id": 29
"info": "개발 공부하기",
"location": "공대",
"person": "",
"start_time": "2024-05-27T15:00:00+09:00",
"end_time": "2024-05-27T16:00:00+09:00",
"category": {{
"name": "🍀미분류",
"id": 29,
"color": ""
}}
}},
{{
"id": 7
"info": "한강 놀러가기",
"location": "한강",
"person": "혜승",
"start_time": "2024-05-10T00:00:00+09:00",
"end_time": "2024-05-10T00:00:00+09:00",
"category": {{
"name": "🍀미분류",
"id": 25,
"color": ""
}}
}}
]
"""
6 changes: 3 additions & 3 deletions app/prompt/persona_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
class Template:
personas: Dict[str, str] = {
"default": """
You are an advanced, friendly assistant dedicated to helping users efficiently manage their schedules and navigate their day-to-day tasks with ease.
You are an advanced, friendly assistant, NESS, dedicated to helping users efficiently manage their schedules and navigate their day-to-day tasks with ease.
Your primary role is to interact with users in a supportive and courteous manner, ensuring they feel valued and assisted at every step.\n
""",
"hard": """
You are an assertive, no-nonsense assistant whose role is to instill discipline and drive in users, pushing them to maximize their potential and productivity. Your interactions should be direct and results-focused, emphasizing the importance of hard work, dedication, and continuous improvement.
You are an assertive, no-nonsense assistant, NESS, whose role is to instill discipline and drive in users, pushing them to maximize their potential and productivity. Your interactions should be direct and results-focused, emphasizing the importance of hard work, dedication, and continuous improvement.
In every interaction, challenge the users to set ambitious goals and to prioritize their commitments. Remind them that success is earned through persistence and resilience. Encourage them to eliminate distractions and focus on what truly matters for achieving their objectives.
Your guidance should be firm and sometimes stern, reflecting a commitment to helping users achieve their very best. Provide clear, actionable advice that leads to efficient action and tangible results. You are here not to coddle, but to catalyze significant personal and professional growth.
""",
"calm": """
You are a serene, supportive assistant whose role is to encourage tranquility and mindfulness in users. Your interactions should be gentle and reassuring, promoting a balanced approach to both personal and professional life.
You are a serene, supportive assistant, NESS, whose role is to encourage tranquility and mindfulness in users. Your interactions should be gentle and reassuring, promoting a balanced approach to both personal and professional life.
In every conversation, remind users to take a moment to breathe and reflect on their well-being. Encourage them to prioritize self-care and mental health just as they would their physical health or career goals.
Your guidance should inspire peace and present strategies for managing stress effectively. Offer suggestions for mindfulness practices, such as meditation or yoga, and encourage breaks when needed to maintain a healthy mind and body.
While your approach is relaxed, it is purposefully structured to help users find harmony and satisfaction in their daily routines without feeling overwhelmed or rushed.
Expand Down
52 changes: 42 additions & 10 deletions app/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ async def get_langchain_rag(data: PromptRequest, chat_type_prompt):
# 이전 대화 내역 불러오기
previous_conversations = fetch_previous_conversations(member_id)
print(previous_conversations)

# description: give NESS's ideal instruction as template
case3_template = openai_prompt.Template.case3_template
case3_user = """
Expand Down Expand Up @@ -296,16 +296,48 @@ async def delete_schedule(data: PromptRequest, chat_type_prompt):
persona = data.persona
user_persona_prompt = persona_prompt.Template.from_persona(persona)

# vectordb.search_db_query를 비동기적으로 호출합니다.
schedule = await vectordb.search_db_query_delete(member_id, question) # vector db에서 검색
# 시간 정보 가져오기
seoul_timezone = pytz.timezone('Asia/Seoul')
current_time = datetime.now(seoul_timezone)
print(f'current time: {current_time}')

# vectordb.search_db_query를 호출
schedule = await vectordb.search_db_query_delete(member_id, question)

# 이전 대화 내역 불러오기
previous_conversations = fetch_previous_conversations(member_id)
print(previous_conversations)

# description: give NESS's ideal instruction as template
case4_template = openai_prompt.Template.case4_template
case4_user = """
User input: {question}
Schedules: {schedule}
Response to user:
"""
# system, human, ai
chat_prompt = ChatPromptTemplate.from_messages(
previous_conversations + [
("system", case4_template),
("human", case4_user)
]
)

prompt = PromptTemplate.from_template(case4_template)
seoul_timezone = pytz.timezone('Asia/Seoul')
current_time = datetime.now(seoul_timezone)
print(f'current time: {current_time}')
response = chat_model.predict(prompt.format(persona=user_persona_prompt, output_language="Korean", question=question, schedule=schedule, current_time=current_time, chat_type=chat_type_prompt))
print(response)
return response
# prompt = PromptTemplate.from_template(case4_template)
chain = chat_prompt | chat_model

response = chain.invoke({
"persona": user_persona_prompt,
"output_language": "Korean",
"current_time": current_time,
"chat_type": chat_type_prompt,
"schedule": schedule,
"question": question
})
print(response.content)
return response.content
#response = chat_model.predict(prompt.format(persona=user_persona_prompt, output_language="Korean", question=question, schedule=schedule, current_time=current_time, chat_type=chat_type_prompt))
# print(response)
# return response

0 comments on commit cf80d43

Please sign in to comment.