Skip to content

Commit 51d58d8

Browse files
author
changuk
committed
Merge branch 'feature/11-prompt-config' of https://github.com/CausalInferenceLab/Lang2SQL into feature/11-prompt-config
2 parents 7130b1e + 68bc8fd commit 51d58d8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

prompt/template.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import re
3+
from datetime import datetime
4+
5+
from langchain_core.prompts import PromptTemplate
6+
from langgraph.prebuilt.chat_agent_executor import AgentState
7+
8+
9+
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)
17+
return template
18+
19+
20+
def apply_prompt_template(prompt_name: str, state: AgentState) -> list:
21+
system_prompt = PromptTemplate(
22+
input_variables=["CURRENT_TIME"],
23+
template=get_prompt_template(prompt_name),
24+
).format(CURRENT_TIME=datetime.now().strftime("%a %b %d %Y %H:%M:%S %z"), **state)
25+
26+
# system prompt template 설정
27+
return [{"role": "system", "content": system_prompt}] + state["messages"]
28+
29+
30+
if __name__ == "__main__":
31+
print(get_prompt_template("prompt_md_sample"))
32+
# print(apply_prompt_template("prompt_md_sample", {"messages": []}))

0 commit comments

Comments
 (0)