Update app.py
Browse files
app.py
CHANGED
@@ -17,13 +17,28 @@ from langchain_anthropic import ChatAnthropic
|
|
17 |
from langchain_community.tools import ShellTool
|
18 |
from langgraph.prebuilt import create_react_agent
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
# Initialize show_system_prompt in session state
|
21 |
if "show_system_prompt" not in st.session_state:
|
22 |
st.session_state.show_system_prompt = False
|
23 |
|
24 |
-
|
25 |
-
if st.button("Show System Prompt" if not st.session_state.show_system_prompt else "Hide System Prompt"):
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Show title and description.
|
29 |
st.title("Coder for NextJS Templates")
|
@@ -158,7 +173,10 @@ else:
|
|
158 |
class AgentState(TypedDict):
|
159 |
messages: Annotated[List[BaseMessage], operator.add]
|
160 |
|
161 |
-
|
|
|
|
|
|
|
162 |
|
163 |
system_prompt_template = """You are an AI specialized in managing and analyzing a GitHub repository for a Next.js blog website.
|
164 |
Your task is to answer user queries about the repository or execute tasks for modifying it.
|
@@ -269,13 +287,21 @@ else:
|
|
269 |
|
270 |
# Recreate the graph with the updated system prompt
|
271 |
global graph
|
|
|
|
|
|
|
|
|
|
|
272 |
graph = create_react_agent(
|
273 |
-
|
274 |
tools=tools,
|
275 |
messages_modifier=st.session_state.system_prompt,
|
276 |
checkpointer=memory
|
277 |
)
|
278 |
|
|
|
|
|
|
|
279 |
# Automatically refresh repo data when keys are provided
|
280 |
if "REPO_CONTENT" not in st.session_state:
|
281 |
refresh_repo_data()
|
|
|
17 |
from langchain_community.tools import ShellTool
|
18 |
from langgraph.prebuilt import create_react_agent
|
19 |
|
20 |
+
if "use_sonnet" not in st.session_state:
|
21 |
+
st.session_state.use_sonnet = False
|
22 |
+
|
23 |
+
col1, col2 = st.columns(2)
|
24 |
+
|
25 |
# Initialize show_system_prompt in session state
|
26 |
if "show_system_prompt" not in st.session_state:
|
27 |
st.session_state.show_system_prompt = False
|
28 |
|
29 |
+
with col1:
|
30 |
+
if st.button("Show System Prompt" if not st.session_state.show_system_prompt else "Hide System Prompt"):
|
31 |
+
st.session_state.show_system_prompt = not st.session_state.show_system_prompt
|
32 |
+
|
33 |
+
with col2:
|
34 |
+
if st.button("Use Sonnet 3.5"):
|
35 |
+
st.session_state.use_sonnet = True
|
36 |
+
|
37 |
+
if st.session_state.use_sonnet:
|
38 |
+
sonnet_api_key = st.text_input("Input Anthropic API Key for Sonnet 3.5", type="password")
|
39 |
+
if sonnet_api_key:
|
40 |
+
os.environ["ANTHROPIC_API_KEY"] = sonnet_api_key
|
41 |
+
|
42 |
|
43 |
# Show title and description.
|
44 |
st.title("Coder for NextJS Templates")
|
|
|
173 |
class AgentState(TypedDict):
|
174 |
messages: Annotated[List[BaseMessage], operator.add]
|
175 |
|
176 |
+
if st.session_state.use_sonnet and "ANTHROPIC_API_KEY" in os.environ:
|
177 |
+
llm = ChatAnthropic(temperature=0, model_name="claude-3-sonnet-20240307")
|
178 |
+
else:
|
179 |
+
llm = ChatAnthropic(temperature=0, model_name="claude-3-haiku-20240307")
|
180 |
|
181 |
system_prompt_template = """You are an AI specialized in managing and analyzing a GitHub repository for a Next.js blog website.
|
182 |
Your task is to answer user queries about the repository or execute tasks for modifying it.
|
|
|
287 |
|
288 |
# Recreate the graph with the updated system prompt
|
289 |
global graph
|
290 |
+
if st.session_state.use_sonnet and "ANTHROPIC_API_KEY" in os.environ:
|
291 |
+
new_llm = ChatAnthropic(temperature=0, model_name="claude-3-sonnet-20240307")
|
292 |
+
else:
|
293 |
+
new_llm = ChatAnthropic(temperature=0, model_name="claude-3-haiku-20240307")
|
294 |
+
|
295 |
graph = create_react_agent(
|
296 |
+
new_llm,
|
297 |
tools=tools,
|
298 |
messages_modifier=st.session_state.system_prompt,
|
299 |
checkpointer=memory
|
300 |
)
|
301 |
|
302 |
+
if st.session_state.use_sonnet and "ANTHROPIC_API_KEY" in os.environ:
|
303 |
+
refresh_repo_data()
|
304 |
+
|
305 |
# Automatically refresh repo data when keys are provided
|
306 |
if "REPO_CONTENT" not in st.session_state:
|
307 |
refresh_repo_data()
|