Skip to content

Commit

Permalink
feat: case 3 챗 컴플리션 변경 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
uommou committed Jul 15, 2024
1 parent 3db4d60 commit 5ef5add
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
3 changes: 0 additions & 3 deletions app/prompt/openai_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ class Template:
Response: Good morning! You have two meetings scheduled for tomorrow: the project status update at 10 AM and the client discussion at 3 PM. Would you like reminders for these, or is there anything else I can assist you with?
Now respond to following User input, based on RAG Retrieval.
User input: {question},
RAG Retrieval: {schedule}
Response:
"""

case4_template = """
Expand Down
50 changes: 40 additions & 10 deletions app/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async def get_langchain_schedule(data: PromptRequest, chat_type_prompt):
# 이전 대화 내역 가져오기
previous_conversations = fetch_previous_conversations(member_id)
print(previous_conversations)

question = data.prompt
persona = data.persona
user_persona_prompt = persona_prompt.Template.from_persona(persona)
Expand All @@ -182,7 +182,7 @@ async def get_langchain_schedule(data: PromptRequest, chat_type_prompt):
chat_prompt = ChatPromptTemplate.from_messages(
previous_conversations + [
("system", case2_template),
("human", "{question}")
("human", "User input: {question}")
]
)

Expand Down Expand Up @@ -231,24 +231,54 @@ async def get_langchain_rag(data: PromptRequest, chat_type_prompt):
model_name=config_normal['MODEL_NAME'], # 모델명
openai_api_key=OPENAI_API_KEY # API 키
)

member_id = data.member_id
question = data.prompt
persona = data.persona
user_persona_prompt = persona_prompt.Template.from_persona(persona)

# vectordb.search_db_query를 비동기적으로 호출합니다.
# 시간 가져오기
seoul_timezone = pytz.timezone('Asia/Seoul')
current_time = datetime.now(seoul_timezone)
print(f'current time: {current_time}')

# 관련 스케줄 가져오기
schedule = await vectordb.search_db_query(member_id, question) # vector db에서 검색

# 이전 대화 내역 불러오기
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 = """
User input: {question},
RAG Retrieval: {schedule}
Response:
"""
#prompt = PromptTemplate.from_template(case3_template)
# system, human, ai
chat_prompt = ChatPromptTemplate.from_messages(
previous_conversations + [
("system", case3_template),
("human", case3_user)
]
)

prompt = PromptTemplate.from_template(case3_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
#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))
# 프롬프트와 모델을 chaining
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

# case 4 : delete schedule
async def delete_schedule(data: PromptRequest, chat_type_prompt):
Expand Down

0 comments on commit 5ef5add

Please sign in to comment.