-
Notifications
You must be signed in to change notification settings - Fork 12
Feature/11 prompt config #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
712c6ee
Merge remote-tracking branch 'origin/6-dbms별-sql-차이를-반영한-few-shot-pro…
nonegom 65b159d
feat: prompt load from prompt file
nonegom c1b39d7
feat: SQL Prompt class and update prompt from file function
nonegom 453f825
feat: chat prompt sample example
nonegom 68bc8fd
feat: markdown prompt example
nonegom a204bbb
feat: prompt load from prompt file
nonegom 96c5fd9
feat: SQL Prompt class and update prompt from file function
nonegom 9917d74
feat: chat prompt sample example
nonegom 402f4a3
feat: markdown prompt example
nonegom 7130b1e
feat: prompt loader
51d58d8
Merge branch 'feature/11-prompt-config' of https://github.com/CausalI…
ee7911f
feat: query prompt를 마크다운 형태로 관리
nonegom 5e9a8ff
feat: remove unuse files
nonegom d8a5cd5
chore: prompt init setting
nonegom ab5d4ae
feat: remove unuse prompy .yaml
nonegom ec6f086
docs: apply ruff
nonegom 9fd52e3
Merge branch 'master' into feature/11-prompt-config
ehddnr301 03c0292
style: apply Black formatter to Python files
ehddnr301 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from langchain.chains.sql_database.prompt import SQL_PROMPTS | ||
| import os | ||
|
|
||
| from langchain_core.prompts import load_prompt | ||
|
|
||
|
|
||
| class SQLPrompt(): | ||
| def __init__(self): | ||
| # os library를 확인해서 SQL_PROMPTS key에 해당하는ㅁ prompt가 있으면, 이를 교체 | ||
| self.sql_prompts = SQL_PROMPTS | ||
| self.target_db_list = list(SQL_PROMPTS.keys()) | ||
| self.prompt_path = '../prompt' | ||
|
|
||
| def update_prompt_from_path(self): | ||
| if os.path.exists(self.prompt_path): | ||
| path_list = os.listdir(self.prompt_path) | ||
| # yaml 파일만 가져옴 | ||
| file_list = [file for file in path_list if file.endswith('.yaml')] | ||
| key_path_dict = {key.split('.')[0]: os.path.join(self.prompt_path, key) for key in file_list if key.split('.')[0] in self.target_db_list} | ||
| # file_list에서 sql_prompts의 key에 해당하는 파일이 있는 것만 가져옴 | ||
| for key, path in key_path_dict.items(): | ||
| self.sql_prompts[key] = load_prompt(path, encoding='utf-8') | ||
| else: | ||
| raise FileNotFoundError(f"Prompt file not found in {self.prompt_path}") | ||
| return False | ||
|
|
||
| if __name__ == '__main__': | ||
| sql_prompts_class = SQLPrompt() | ||
| print(sql_prompts_class.sql_prompts['mysql']) | ||
| print(sql_prompts_class.update_prompt_from_path()) | ||
|
|
||
| print(sql_prompts_class.sql_prompts['mysql']) | ||
| print(sql_prompts_class.sql_prompts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Role | ||
|
|
||
| 당신은 데이터 분석 전문가(데이터 분석가 페르소나)입니다. | ||
| 사용자의 질문을 기반으로, 주어진 테이블과 컬럼 정보를 활용하여 적절한 SQL 쿼리를 생성하세요. | ||
|
|
||
| # 주의사항 | ||
| - 사용자의 질문이 다소 모호하더라도, 주어진 데이터를 참고하여 합리적인 가정을 통해 SQL 쿼리를 완성하세요. | ||
| - 불필요한 재질문 없이, 가능한 가장 명확한 분석 쿼리를 만들어 주세요. | ||
| - 최종 출력 형식은 반드시 아래와 같아야 합니다. | ||
|
|
||
| # Output Example | ||
| 최종 형태 예시: | ||
| <SQL> | ||
| ```sql | ||
| SELECT COUNT(DISTINCT user_id) | ||
| FROM stg_users | ||
| ``` | ||
|
|
||
| <해석> | ||
| ```plaintext (max_length_per_line=100) | ||
| 이 쿼리는 stg_users 테이블에서 고유한 사용자의 수를 계산합니다. | ||
| 사용자는 유니크한 user_id를 가지고 있으며 | ||
| 중복을 제거하기 위해 COUNT(DISTINCT user_id)를 사용했습니다. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Role | ||
|
|
||
| 당신은 데이터 분석 전문가(데이터 분석가 페르소나)입니다. | ||
| 현재 subscription_activities, contract_activities, marketing_activities, | ||
| sales_activities, success_activities, support_activities, trial_activities 데이터를 | ||
| 보유하고 있으며, 사용자의 질문이 모호할 경우에도 우리가 가진 데이터를 기반으로 | ||
| 충분히 답변 가능한 형태로 질문을 구체화해 주세요. | ||
|
|
||
| # 주의사항: | ||
| - 사용자에게 추가 정보를 요구하는 ‘재질문(추가 질문)’을 하지 마세요. | ||
| - 질문에 포함해야 할 요소(예: 특정 기간, 대상 유저 그룹, 분석 대상 로그 종류 등)가 | ||
| 불충분하더라도, 합리적으로 추론해 가정한 뒤 | ||
| 답변에 충분한 질문 형태로 완성해 주세요. | ||
| 예시: | ||
| 사용자가 "유저 이탈 원인이 궁금해요"라고 했다면, | ||
| 재질문 형식이 아니라 | ||
| "최근 1개월 간의 접속·결제 로그를 기준으로, | ||
| 주로 어떤 사용자가 어떤 과정을 거쳐 이탈하는지를 분석해야 한다"처럼 | ||
| 분석 방향이 명확해진 질문 한 문장(또는 한 문단)으로 정리해 주세요. | ||
|
|
||
| # Output Example | ||
|
|
||
| 최종 출력 형식 예시: | ||
| ------------------------------ | ||
| 구체화된 질문: | ||
| "최근 1개월 동안 고액 결제 경험이 있는 유저가 | ||
| 행동 로그에서 이탈 전 어떤 패턴을 보였는지 분석" | ||
|
|
||
| 가정한 조건: | ||
| - 최근 1개월치 행동 로그와 결제 로그 중심 | ||
| - 고액 결제자(월 결제액 10만 원 이상) 그룹 대상으로 한정 | ||
| ------------------------------ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import os | ||
| import re | ||
| from datetime import datetime | ||
|
|
||
| from langchain_core.prompts import PromptTemplate | ||
| from langgraph.prebuilt.chat_agent_executor import AgentState | ||
|
|
||
|
|
||
| def get_prompt_template(prompt_name: str) -> str: | ||
| try: | ||
| with open(os.path.join(os.path.dirname(__file__), f"{prompt_name}.md"), "r", encoding="utf-8") as f: | ||
| template = f.read() | ||
| except FileNotFoundError: | ||
| raise FileNotFoundError(f"경고: '{prompt_name}.md' 파일을 찾을 수 없습니다.") | ||
| return template | ||
|
|
||
| if __name__ == "__main__": | ||
| print(get_prompt_template("system_prompt")) | ||
| # print(apply_prompt_template("prompt_md_sample", {"messages": []})) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗제 환경에서는 에러가 나네요...ㅜㅜ
디버깅
ls -ltra /home/pseudo.dwlee038/miniconda3/lib/python3.12/site-packages/prompt/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 해당 코드를 받으신 이후
pip install .을 해보셨을까요?아니면,
pip install -e .을 해서 새로 build가 필요할 것 같습니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pip install -e .로 진행하니 됩니다!