File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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": []}))
You can’t perform that action at this time.
0 commit comments