Skip to content

Commit

Permalink
Merge pull request #71 from studio-recoding/feat/case2-multiple-sched…
Browse files Browse the repository at this point in the history
…ules

feat: 일정 여러 개 추가
  • Loading branch information
uommou authored Jun 26, 2024
2 parents 3908597 + f00c2c8 commit 9119f32
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 34 deletions.
10 changes: 5 additions & 5 deletions app/prompt/openai_config.ini
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[NESS_NORMAL]
TEMPERATURE = 0.5
MAX_TOKENS = 1500
MODEL_NAME = gpt-4
MODEL_NAME = gpt-4-turbo

[NESS_CASE]
TEMPERATURE = 0
MAX_TOKENS = 1000
MODEL_NAME = gpt-4
MODEL_NAME = gpt-4-turbo

[NESS_RECOMMENDATION]
TEMPERATURE = 1
MAX_TOKENS = 2048
MODEL_NAME = gpt-4
MODEL_NAME = gpt-4-turbo

[NESS_TAGS]
TEMPERATURE = 0.5
MAX_TOKENS = 2048
MODEL_NAME = gpt-4
MODEL_NAME = gpt-4-turbo

[NESS_EMAIL]
TEMPERATURE = 0.5
MAX_TOKENS = 2048
MODEL_NAME = gpt-4
MODEL_NAME = gpt-4-turbo
64 changes: 39 additions & 25 deletions app/prompt/openai_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Template:
You will receive a list of the user's schedule information. Your task is to understand each schedule and generate a comment for each. There are a few rules you must follow in your comments:
1. YOU MUST USE {output_language} TO RESPOND TO THE USER INPUT.
2. Each comment should be concise, relevant to the schedule details, and realistic.
2. Each comment should be concise, relevant to the schedule details, and realistic. You are able to give advice to the user, if needed.
3. Comments should be in sentence form, suitable for displaying alongside the schedule.
4. Return the comments in a list format, without any additional commentary.
Expand Down Expand Up @@ -116,40 +116,54 @@ class Template:
case2_template = """
{persona}
{chat_type}
The user's input contains information about a new event they want to add to their schedule. You have two tasks to perform:
The user's input contains information about several new events 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, start_time, end_time, and category. The category should include the name, id, and color.
2. Organize the events the user wants to add into a json format for saving 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.
- 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.
- start_time: 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}.
- end_time: If the user's event information includes an end time, save that date and time in datetime format.
- start_time: If the user's event information includes a specific date and time, save that date and time in ISO 8601 datetime format. Dates should be organized based on the current time. Current time is {current_time}.
- end_time: If the user's event information includes an end time, save that date and time in ISO 8601 datetime format.
- category: Choose the most appropriate category for the event from the following list: {categories}. The category should include the name, id, and color.
Separate the outputs for tasks 1 and 2 with a special token <separate>.
Example for one-shot learning:
User input: I have a meeting with Dr. Smith at her office on March 3rd from 10am to 11am.
User input: I have a meeting with Dr. Smith at her office on March 3rd from 10am to 11am, and a dinner with John at the Italian restaurant on March 4th at 7pm.
Response to user:
Shall I add your meeting with Dr. Smith at her office on March 3rd from 10am to 11am to your schedule?
Shall I add your meeting with Dr. Smith at her office on March 3rd from 10am to 11am and your dinner with John at the Italian restaurant on March 4th at 7pm to your schedule?
<separate>
{{
"info": "meeting with Dr. Smith",
"location": "Dr. Smith's office",
"person": "Dr. Smith",
"start_time": "2023-03-03T10:00:00",
"end_time": "2023-03-03T11:00:00",
"category": {{
"name": "Work",
"id": 1,
"color": "#FF0000"
}}
}}
[
{
"info": "meeting with Dr. Smith",
"location": "Dr. Smith's office",
"person": "Dr. Smith",
"start_time": "2023-03-03T10:00:00+09:00",
"end_time": "2023-03-03T11:00:00+09:00",
"category": {
"name": "Work",
"id": 1,
"color": "#FF0000"
}
},
{
"info": "dinner with John",
"location": "Italian restaurant",
"person": "John",
"start_time": "2023-03-04T19:00:00+09:00",
"end_time": null, // Assuming end time is not specified
"category": {
"name": "Personal",
"id": 2,
"color": "#00FF00"
}
}
]
User input: {question}
Response to user:
"""

Expand Down
13 changes: 10 additions & 3 deletions app/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from app.prompt import openai_prompt, persona_prompt

import app.database.chroma_db as vectordb
import pytz

router = APIRouter(
prefix="/chat",
Expand Down Expand Up @@ -95,7 +96,9 @@ async def get_langchain_normal(data: PromptRequest, chat_type_prompt): # case 1
my_template = openai_prompt.Template.case1_template

prompt = PromptTemplate.from_template(my_template)
current_time = datetime.now()
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, current_time=current_time, chat_type=chat_type_prompt))
print(response)
return response
Expand Down Expand Up @@ -128,7 +131,9 @@ async def get_langchain_schedule(data: PromptRequest, chat_type_prompt):
case2_template = openai_prompt.Template.case2_template

prompt = PromptTemplate.from_template(case2_template)
current_time = datetime.now()
seoul_timezone = pytz.timezone('Asia/Seoul')
current_time = datetime.now(seoul_timezone)
print(f'current time: {current_time}')

# OpenAI 프롬프트에 데이터 통합
response = chat_model.predict(
Expand Down Expand Up @@ -172,7 +177,9 @@ async def get_langchain_rag(data: PromptRequest, chat_type_prompt):
case3_template = openai_prompt.Template.case3_template

prompt = PromptTemplate.from_template(case3_template)
current_time = datetime.now()
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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ python-dotenv==1.0.0
starlette==0.35.1
pydantic==2.5.3
sentence-transformers==2.5.1
pymysql
pymysql
pytz

0 comments on commit 9119f32

Please sign in to comment.