Skip to content

Commit

Permalink
Merge pull request #67 from studio-recoding/dev
Browse files Browse the repository at this point in the history
fix: chat2 완성
  • Loading branch information
uommou authored May 26, 2024
2 parents 4379e94 + 19e9787 commit 43f950c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 42 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
env:
OPENAI_API_KEY: ${{secrets.OPENAI_API_KEY}}
CHROMA_DB_IP_ADDRESS: ${{secrets.CHROMA_DB_IP_ADDRESS}}
RDS_HOST: ${{ secrets.RDS_HOST }}
RDS_USER: ${{ secrets.RDS_USER }}
RDS_PASSWORD: ${{ secrets.RDS_PASSWORD }}
RDS_DATABASE: ${{ secrets.RDS_DATABASE }}

steps:
- name: Checkout
Expand All @@ -27,6 +31,10 @@ jobs:
run: |
echo "CHROMA_DB_IP_ADDRESS=${{ secrets.CHROMA_DB_IP_ADDRESS }}" >> .env
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "RDS_HOST=${{ secrets.RDS_HOST }}" >> .env
echo "RDS_USER=${{ secrets.RDS_USER }}" >> .env
echo "RDS_PASSWORD=${{ secrets.RDS_PASSWORD }}" >> .env
echo "RDS_DATABASE=${{ secrets.RDS_DATABASE }}" >> .env
shell: bash

- name: Setup docker buildx
Expand Down Expand Up @@ -84,4 +92,8 @@ jobs:
docker run -d -p 80:80 --name ${{ env.NAME }} --restart always \
-e CHROMA_DB_IP_ADDRESS=${{ secrets.CHROMA_DB_IP_ADDRESS }} \
-e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \
-e RDS_HOST=${{ secrets.RDS_HOST }} \
-e RDS_USER=${{ secrets.RDS_USER }} \
-e RDS_PASSWORD=${{ secrets.RDS_PASSWORD }} \
-e RDS_DATABASE=${{ secrets.RDS_DATABASE }} \
${{ env.DOCKER_IMAGE }}:latest
1 change: 1 addition & 0 deletions app/database/connect_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
def get_rds_connection():
return pymysql.connect(
host=os.getenv('RDS_HOST'),
port=3306,
user=os.getenv('RDS_USER'),
password=os.getenv('RDS_PASSWORD'),
database=os.getenv('RDS_DATABASE'),
Expand Down
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 = 2048
MODEL_NAME = gpt-4
MODEL_NAME = gpt-4o

[NESS_CASE]
TEMPERATURE = 0
MAX_TOKENS = 2048
MODEL_NAME = gpt-4
MODEL_NAME = gpt-4o

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

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

[NESS_EMAIL]
TEMPERATURE = 0.5
MAX_TOKENS = 2048
MODEL_NAME = gpt-4
MODEL_NAME = gpt-4o
73 changes: 40 additions & 33 deletions app/prompt/openai_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ class Template:
User Chat: {question}
Answer:
"""

chat_type_stt_template = """
You should keep in mind that this user's input was written using speech to text technology.
Therefore, there may be inaccuracies in the text due to errors in the STT process.
You need to consider this aspect when performing the given task.
"""

chat_type_user_template = """
"""

case1_template = """
{persona}
{chat_type}
Expand All @@ -88,39 +91,43 @@ 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:
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.
- 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.
- category: Choose the most appropriate category for the event from the following list: {categories}.
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.
Response to user:
Shall I add your meeting with Dr. Smith at her office on March 3rd from 10am to 11am 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": "Work"
}}
User input: {question}
Response to user:
{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:
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.
- 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.
- 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.
Response to user:
Shall I add your meeting with Dr. Smith at her office on March 3rd from 10am to 11am 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"
}}
}}
User input: {question}
Response to user:
"""

case3_template = """
Expand Down
10 changes: 6 additions & 4 deletions app/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ async def get_langchain_schedule(data: PromptRequest, chat_type_prompt):
print("running case 2")
member_id = data.member_id
categories = fetch_category_classification_data(member_id)
# 카테고리 데이터를 텍스트로 변환 (JSON 형식으로 변환)
categories_text = ", ".join([category['name'] for category in categories])
print(categories_text)
# 카테고리 데이터를 딕셔너리 형태로 변환
categories_dict = [
{"name": category['name'], "id": category['category_id'], "color": category['color']}
for category in categories
]

# description: use langchain
config_normal = config['NESS_NORMAL']
Expand All @@ -136,7 +138,7 @@ async def get_langchain_schedule(data: PromptRequest, chat_type_prompt):
question=question,
current_time=current_time,
chat_type=chat_type_prompt,
categories=categories_text # 카테고리 데이터를 프롬프트에 포함
categories=categories_dict # 카테고리 데이터를 프롬프트에 포함
)
)

Expand Down

0 comments on commit 43f950c

Please sign in to comment.