Skip to content

Commit

Permalink
feature: apply RAG after sql filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyoon9704 committed Jan 9, 2025
1 parent d957fd1 commit 50a5a54
Show file tree
Hide file tree
Showing 18 changed files with 1,421 additions and 1,254 deletions.
62 changes: 62 additions & 0 deletions configs/examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
EXAMPLES = [
{
"question": "부산역 근처 돼지국밥 맛집 알려주세요.",
"sql": "SELECT * FROM RESTAURANTS WHERE DISTRICT = '동구' AND MENU_NAME LIKE '%돼지국밥%' ORDER BY RATING DESC",
"source": "restaurants",
},
{
"question": "광안리 근처에서 아이들이랑 가기 좋은 식당 추천해주세요.",
"sql": "SELECT * FROM RESTAURANTS WHERE DISTRICT = '수영구' AND MENU_FOR_CHILDREN_YN = True ORDER BY RATING DESC",
"source": "restaurants",
},
{
"question": "주차가능한 식당 알려주세요.",
"sql": "SELECT * FROM RESTAURANTS WHERE PARKING_LON_YN = True ORDER BY RATING DESC",
"source": "restaurants",
},
{
"question": "아침먹을 수 있는 식당 알려주세요.",
"sql": "SELECT * FROM RESTAURANTS WHERE BREAKFAST_YN = True ORDER BY RATING DESC",
"source": "restaurants",
},
{
"question": "예약가능한 밀면 맛집 알려주세요.",
"sql": "SELECT * FROM RESTAURANTS WHERE MENU_NAME LIKE '%밀면%' and RESERVABLE = True ORDER BY RATING DESC",
"source": "restaurants",
},
{
"question": "서구에서 부모님 모시고 가기 좋은 자연관광지 추천해주세요",
"sql": "SELECT * FROM TOURIST_SPOTS WHERE RECOMMENDED_GROUP LIKE '%부모%' and CATEGORY LIKE '%자연%",
"source": "tourist_spots",
},
{
"question": "사진찍기 좋은 관광지 알려주세요.",
"sql": "SELECT * FROM TOURIST_SPOTS",
"source": "tourist_spots",
},
{
"question": "아이들이랑 가기 좋은 공원 추천해주세요.",
"sql": "SELECT * FROM TOURIST_SPOTS WHERE CATEGORY LIKE '%공원%' and RECOMMENDED_GROUP LIKE '%아이%'",
"source": "tourist_spots",
},
{
"question": "봄에 가기 좋은 관광지 추천해주세요",
"sql": "SELECT * FROM TOURIST_SPOTS WHERE SEASON_NM LIKE '%봄%'",
"source": "tourist_spots",
},
{
"question": "부산역 근처 관광지 추천해주세요",
"sql": "SELECT * FROM TOURIST_SPOTS WHERE DISTRICT = '동구'",
"source": "tourist_spots",
},
{
"question": "광안리 근처 관광지 추천해주세요",
"sql": "SELECT * FROM TOURIST_SPOTS WHERE DISTRICT = '사하구'",
"source": "tourist_spots",
},
{
"question": "해운대 근처 관광지 추천해주세요",
"sql": "SELECT * FROM TOURIST_SPOTS WHERE DISTRICT = '해운대구'",
"source": "tourist_spots",
},
]
23 changes: 15 additions & 8 deletions configs/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
Returns "web" if it is not related to tourist attractions or restaurants, such as weather or transportation.
"""

# Template for SQL generation (initial attempt)
SQL_GENERATION_TEMPLATE = PromptTemplate(
input_variables=["question", "datasource", "schema", "external_knowledge"],
# Template for SQL generation (retry attempt)
SQL_RETRY_TEMPLATE = PromptTemplate(
input_variables=[
"question",
"data_source",
"examples",
"schema",
"external_knowledge",
"previous_answer",
],
template="""
You are an expert in generating SQL queries. Your task is to create SQL queries based on the user's question and the provided schema.
Expand All @@ -33,17 +40,17 @@
{examples}
<QUESTION> {question} </QUESTION>
""",
""",
)

# Template for SQL generation (retry attempt)
SQL_RETRY_TEMPLATE = PromptTemplate(
# Template for SQL generation (initial attempt)
SQL_GENERATION_TEMPLATE = PromptTemplate(
input_variables=[
"question",
"datasource",
"data_source",
"examples",
"schema",
"external_knowledge",
"previous_answer",
],
template="""
You are an expert in generating SQL queries. Your task is to create SQL queries based on the user's question and the provided schema. You must follow these rules:
Expand Down
1,958 changes: 979 additions & 979 deletions data/busan_restrau_20to24_witch_eng_data.csv → data/RESTAURANTS.csv

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions data/TOURIST_SPOTS.csv

Large diffs are not rendered by default.

101 changes: 0 additions & 101 deletions data/내국인 관심 관광지_수정.csv

This file was deleted.

101 changes: 0 additions & 101 deletions data/외국인 관심 관광지_수정.csv

This file was deleted.

Loading

0 comments on commit 50a5a54

Please sign in to comment.