Skip to content

Commit

Permalink
Merge pull request #48 from studio-recoding/fix/chat
Browse files Browse the repository at this point in the history
[fix] chat2에서 현재 시간 기준 추가
  • Loading branch information
uommou authored Apr 14, 2024
2 parents e73f1ca + 4b01946 commit 83d82c7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
53 changes: 27 additions & 26 deletions app/prompt/openai_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,39 @@ class Template:
Answer:
"""
case1_template = """
You are a friendly assistant who helps users manage their schedules. Respond kindly to the user's input. YOU MUST USE {output_language} TO RESPOND TO THE USER INPUT.
User input: {question}
"""
You are a friendly assistant, NESS. NESS helps users manage their schedules. Respond kindly to the user's input. YOU MUST USE {output_language} TO RESPOND TO THE USER INPUT.
User input: {question}
"""
case2_template = """
You are a friendly assistant who helps users manage their schedules. The user's input contains information about a new event they want to add to their schedule. You have two tasks to perform:
You are a friendly assistant who helps users manage their schedules. The user's input contains information about a new event they want to add to 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. Organize the event the user wants to add into a json format for saving in a database. The returned json will have keys for info, location, person, and date.
- info: Summarizes what the user wants to do. This value must always be present.
- location: If the user's event information includes a place, save that place as the value.
- person: If the user's event mentions a person they want to include, save that person as the value.
- date: If the user's event information includes a specific date and time, save that date and time in datetime format.
Separate the outputs for tasks 1 and 2 with a special token <separate>.
1. Respond kindly to the user's input. YOU MUST USE {output_language} TO RESPOND TO THE USER INPUT.
2. Organize the event the user wants to add into a json format for saving in a database. The returned json will have keys for info, location, person, and date.
- info: Summarizes what the user wants to do. This value must always be present.
- location: If the user's event information includes a place, save that place as the value.
- person: If the user's event mentions a person they want to include, save that person as the value.
- date: If the user's event information includes a specific date and time, save that date and time in datetime format. Dates should be organized based on the current time at the user's location. Current time is {current_time}.
Separate the outputs for tasks 1 and 2 with a special token <separate>.
Example for one-shot learning:
Example for one-shot learning:
User input: "I have a meeting with Dr. Smith at her office on March 3rd at 10am."
User input: "I have a meeting with Dr. Smith at her office on March 3rd at 10am."
Response to user:
"I've added your meeting with Dr. Smith at her office on March 3rd at 10am to your schedule. Is there anything else you'd like to add or modify?"
<separate>
{{
"info": "meeting with Dr. Smith",
"location": "Dr. Smith's office",
"person": "Dr. Smith",
"date": "2023-03-03T10:00:00"
}}
Response to user:
"I've added your meeting with Dr. Smith at her office on March 3rd at 10am to your schedule. Is there anything else you'd like to add or modify?"
<separate>
{{
"info": "meeting with Dr. Smith",
"location": "Dr. Smith's office",
"person": "Dr. Smith",
"date": "2023-03-03T10:00:00"
}}
User input: {question}
Response to user:
"""

User input: {question}
Response to user:
"""
case3_template = """
You are an advanced, friendly assistant 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.
Expand Down
12 changes: 8 additions & 4 deletions app/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from fastapi import APIRouter, HTTPException, status
from langchain_community.chat_models import ChatOpenAI
from langchain_core.prompts import PromptTemplate
from datetime import datetime

from app.dto.openai_dto import PromptRequest, ChatResponse, ChatCaseResponse
from app.prompt import openai_prompt
Expand Down Expand Up @@ -57,9 +58,11 @@ async def get_langchain_case(data: PromptRequest) -> ChatCaseResponse:
response = await get_langchain_rag(data)

else:
print("wrong case classification")
# 적절한 HTTP 상태 코드와 함께 오류 메시지를 반환하거나, 다른 처리를 할 수 있습니다.
raise HTTPException(status_code=400, detail="Wrong case classification")
# print("wrong case classification")
# # 적절한 HTTP 상태 코드와 함께 오류 메시지를 반환하거나, 다른 처리를 할 수 있습니다.
# raise HTTPException(status_code=400, detail="Wrong case classification")
response = "좀 더 명확한 요구가 필요해요. 다시 한 번 얘기해주실 수 있나요?"
case = "Exception"

return ChatCaseResponse(ness=response, case=case)

Expand Down Expand Up @@ -104,7 +107,8 @@ async def get_langchain_schedule(data: PromptRequest):
case2_template = openai_prompt.Template.case2_template

prompt = PromptTemplate.from_template(case2_template)
response = chat_model.predict(prompt.format(output_language="Korean", question=question))
current_time = datetime.now()
response = chat_model.predict(prompt.format(output_language="Korean", question=question, current_time=current_time))
print(response)
return response

Expand Down

0 comments on commit 83d82c7

Please sign in to comment.