Skip to content

Commit 7130b1e

Browse files
author
changuk
committed
feat: prompt loader
1 parent 402f4a3 commit 7130b1e

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

llm_utils/tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def _get_table_info() -> Dict[str, str]:
3232
table_description = fetcher.get_table_description(urn)
3333
if table_name and table_description:
3434
table_info[table_name] = table_description
35+
print(f'table_name {urn}')
3536
return table_info
3637

3738

prompt/system_prompt.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Role
2+
3+
당신은 데이터 분석 전문가(데이터 분석가 페르소나)입니다.
4+
사용자의 질문을 기반으로, 주어진 테이블과 컬럼 정보를 활용하여 적절한 SQL 쿼리를 생성하세요.
5+
6+
# 주의사항:
7+
- 사용자의 질문이 다소 모호하더라도, 주어진 데이터를 참고하여 합리적인 가정을 통해 SQL 쿼리를 완성하세요.
8+
- 불필요한 재질문 없이, 가능한 가장 명확한 분석 쿼리를 만들어 주세요.
9+
- 최종 출력 형식은 반드시 아래와 같아야 합니다.
10+
11+
# Output Example
12+
최종 형태 예시:
13+
<SQL>
14+
```sql
15+
SELECT COUNT(DISTINCT user_id)
16+
FROM stg_users
17+
```
18+
19+
<해석>
20+
```plaintext (max_length_per_line=100)
21+
이 쿼리는 stg_users 테이블에서 고유한 사용자의 수를 계산합니다.
22+
사용자는 유니크한 user_id를 가지고 있으며
23+
중복을 제거하기 위해 COUNT(DISTINCT user_id)를 사용했습니다.
24+
25+
# Input Example
26+
{user_query}

prompt/template.py renamed to prompt/template_loader.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77

88

99
def get_prompt_template(prompt_name: str) -> str:
10-
template = open(os.path.join(os.path.dirname(__file__), f"{prompt_name}.md")).read()
11-
12-
# Escape curly braces using backslash (중괄호를 문자로 처리)
13-
template = template.replace("{", "{{").replace("}", "}}")
14-
15-
# Replace `<<VAR>>` with `{VAR}`
16-
template = re.sub(r"<<([^>>]+)>>", r"{\1}", template)
10+
try:
11+
with open(os.path.join(os.path.dirname(__file__), f"{prompt_name}.md"), "r", encoding="utf-8") as f:
12+
template = f.read()
13+
except FileNotFoundError:
14+
raise FileNotFoundError(f"경고: '{prompt_name}.md' 파일을 찾을 수 없습니다.")
1715
return template
1816

1917

@@ -28,5 +26,5 @@ def apply_prompt_template(prompt_name: str, state: AgentState) -> list:
2826

2927

3028
if __name__ == "__main__":
31-
print(get_prompt_template("prompt_md_sample"))
29+
print(get_prompt_template("system_prompt"))
3230
# print(apply_prompt_template("prompt_md_sample", {"messages": []}))

0 commit comments

Comments
 (0)