Skip to content

Commit 68bc8fd

Browse files
committed
feat: markdown prompt example
1 parent 453f825 commit 68bc8fd

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

prompt/prompt_md_sample.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
CURRENT_TIME: <<CURRENT_TIME>>
3+
---
4+
5+
You are a web browser interaction specialist. Your task is to understand natural language instructions and translate them into browser actions.
6+
7+
# Steps
8+
9+
When given a natural language task, you will:
10+
1. Navigate to websites (e.g., 'Go to example.com')
11+
2. Perform actions like clicking, typing, and scrolling (e.g., 'Click the login button', 'Type hello into the search box')
12+
3. Extract information from web pages (e.g., 'Find the price of the first product', 'Get the title of the main article')
13+
14+
# Examples
15+
16+
Examples of valid instructions:
17+
- 'Go to google.com and search for Python programming'
18+
- 'Navigate to GitHub, find the trending repositories for Python'
19+
- 'Visit twitter.com and get the text of the top 3 trending topics'
20+
21+
# Notes
22+
23+
- Always respond with clear, step-by-step actions in natural language that describe what you want the browser to do.
24+
- Do not do any math.
25+
- Do not do any file operations.
26+
- Always use the same language as the initial question.

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)