seansullivan commited on
Commit
96940db
·
verified ·
1 Parent(s): 4b13c32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -45,6 +45,8 @@ github_token = st.text_input("Enter your Github Token", type="password")
45
 
46
  anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
47
 
 
 
48
  if not (github_repo_url and github_token and anthropic_api_key):
49
  st.info("Please add your Github Repo URL and Github Personal Token to continue.", icon="🗝️")
50
  else:
@@ -280,14 +282,19 @@ else:
280
  stack.append((item['path'], item['url']))
281
 
282
  return result
283
-
 
 
 
 
 
284
  def refresh_repo_data():
285
  repo_contents = process_repo(github_repo_url)
286
  repo_contents_json = json.dumps(repo_contents, ensure_ascii=False, indent=2)
287
  st.session_state.REPO_CONTENT = repo_contents_json
288
  st.success("Repository content refreshed successfully.")
289
 
290
- # Update the system prompts with the new repo content
291
  st.session_state.task_system_prompt = task_system_prompt_template.format(REPO_CONTENT=st.session_state.REPO_CONTENT)
292
  st.session_state.qa_system_prompt = qa_system_prompt_template.format(REPO_CONTENT=st.session_state.REPO_CONTENT)
293
 
@@ -304,7 +311,6 @@ else:
304
  messages_modifier=st.session_state.task_system_prompt,
305
  checkpointer=memory
306
  )
307
- graph_tools = []
308
  qa_graph = create_react_agent(
309
  new_llm,
310
  tools = graph_tools,
@@ -319,11 +325,17 @@ else:
319
  if "REPO_CONTENT" not in st.session_state:
320
  refresh_repo_data()
321
 
322
- # Initialize system_prompt in session state
323
- if "system_prompt" not in st.session_state:
324
- st.session_state.system_prompt = system_prompt_template.format(REPO_CONTENT=st.session_state.REPO_CONTENT)
325
-
326
- # Create separate graphs for Task and Q/A modes
 
 
 
 
 
 
327
  task_graph = create_react_agent(
328
  llm,
329
  tools=tools,
@@ -333,7 +345,9 @@ else:
333
 
334
  qa_graph = create_react_agent(
335
  llm,
336
- messages_modifier=st.session_state.qa_system_prompt
 
 
337
  )
338
 
339
  async def run_github_editor(query: str, thread_id: str = "default"):
 
45
 
46
  anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
47
 
48
+ graph_tools = []
49
+
50
  if not (github_repo_url and github_token and anthropic_api_key):
51
  st.info("Please add your Github Repo URL and Github Personal Token to continue.", icon="🗝️")
52
  else:
 
282
  stack.append((item['path'], item['url']))
283
 
284
  return result
285
+ # Instead, add this block after the radio button for mode selection:
286
+ if "task_system_prompt" not in st.session_state or "qa_system_prompt" not in st.session_state:
287
+ st.session_state.task_system_prompt = task_system_prompt_template.format(REPO_CONTENT="")
288
+ st.session_state.qa_system_prompt = qa_system_prompt_template.format(REPO_CONTENT="")
289
+
290
+ # Modify the refresh_repo_data() function:
291
  def refresh_repo_data():
292
  repo_contents = process_repo(github_repo_url)
293
  repo_contents_json = json.dumps(repo_contents, ensure_ascii=False, indent=2)
294
  st.session_state.REPO_CONTENT = repo_contents_json
295
  st.success("Repository content refreshed successfully.")
296
 
297
+ # Update both system prompts with the new repo content
298
  st.session_state.task_system_prompt = task_system_prompt_template.format(REPO_CONTENT=st.session_state.REPO_CONTENT)
299
  st.session_state.qa_system_prompt = qa_system_prompt_template.format(REPO_CONTENT=st.session_state.REPO_CONTENT)
300
 
 
311
  messages_modifier=st.session_state.task_system_prompt,
312
  checkpointer=memory
313
  )
 
314
  qa_graph = create_react_agent(
315
  new_llm,
316
  tools = graph_tools,
 
325
  if "REPO_CONTENT" not in st.session_state:
326
  refresh_repo_data()
327
 
328
+ # Modify the code that displays the current system prompt:
329
+ if st.session_state.show_system_prompt:
330
+ current_prompt = st.session_state.task_system_prompt if mode == "Task" else st.session_state.qa_system_prompt
331
+ st.text_area("Current System Prompt", current_prompt, height=300)
332
+
333
+ # Update the graph initialization:
334
+ if st.session_state.use_sonnet and "ANTHROPIC_API_KEY" in os.environ:
335
+ llm = ChatAnthropic(temperature=0, model_name="claude-3-5-sonnet-20240620")
336
+ else:
337
+ llm = ChatAnthropic(temperature=0, model_name="claude-3-haiku-20240307")
338
+
339
  task_graph = create_react_agent(
340
  llm,
341
  tools=tools,
 
345
 
346
  qa_graph = create_react_agent(
347
  llm,
348
+ tools=graph_tools,
349
+ messages_modifier=st.session_state.qa_system_prompt,
350
+ checkpointer=memory
351
  )
352
 
353
  async def run_github_editor(query: str, thread_id: str = "default"):