aasherkamal216 commited on
Commit
7b5d541
·
unverified ·
1 Parent(s): c4ce9c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -4,7 +4,7 @@ from langchain_groq import ChatGroq
4
  from langchain_community.utilities import ArxivAPIWrapper, WikipediaAPIWrapper
5
  from langchain_community.tools import ArxivQueryRun, WikipediaQueryRun, DuckDuckGoSearchRun
6
  from langchain.agents import initialize_agent, AgentType
7
- from langchain.callbacks import StreamlitCallbackHandler
8
  dotenv.load_dotenv()
9
 
10
  ## Wikipedia Tool
@@ -21,7 +21,15 @@ st.set_page_config(page_icon=":mag:", page_title="Tools & Agent")
21
  st.title(":green[Langchain] Search Agent")
22
 
23
  with st.sidebar:
24
- api_key = st.text_input("Enter Your Groq API Key:", type="password")
 
 
 
 
 
 
 
 
25
 
26
  if "messages" not in st.session_state:
27
  st.session_state["messages"] = [
@@ -41,10 +49,13 @@ if api_key:
41
 
42
  search_agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
43
  agent_executor_kwargs={"handle_parsing_errors": True})
44
- with st.chat_message("assistant"):
45
- st_callback = StreamlitCallbackHandler(st.container(), expand_new_thoughts=True)
46
- response = search_agent.run(st.session_state.messages, callbacks=[st_callback])
47
- st.write(response)
48
- st.session_state.messages.append({"role": "assistant", "content": response})
 
 
 
49
  else:
50
- st.info("Please enter your API Key to proceed")
 
4
  from langchain_community.utilities import ArxivAPIWrapper, WikipediaAPIWrapper
5
  from langchain_community.tools import ArxivQueryRun, WikipediaQueryRun, DuckDuckGoSearchRun
6
  from langchain.agents import initialize_agent, AgentType
7
+ from langchain_community.callbacks.streamlit import StreamlitCallbackHandler
8
  dotenv.load_dotenv()
9
 
10
  ## Wikipedia Tool
 
21
  st.title(":green[Langchain] Search Agent")
22
 
23
  with st.sidebar:
24
+ with st.popover("Add Groq API Key", use_container_width=True):
25
+ api_key = st.text_input("Get Your Groq API Key [Here](https://console.groq.com/keys)", type="password")
26
+ st.divider()
27
+ st.markdown("<h1 style='text-align: center; font-size: 30px;'>About the App✨</h1>", unsafe_allow_html=True)
28
+ st.write("""Hi there! This is a langchain search agent app. First, you have to
29
+ introduce your Groq API key. Then type your question and hit Enter,
30
+ the assistant will step by step retrieve the information relevant to
31
+ your question from Wikipedia, Arxiv and DuckDuckGo Search and then it'll
32
+ answer your question based on that information.""")
33
 
34
  if "messages" not in st.session_state:
35
  st.session_state["messages"] = [
 
49
 
50
  search_agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
51
  agent_executor_kwargs={"handle_parsing_errors": True})
52
+ try:
53
+ with st.chat_message("assistant"):
54
+ st_callback = StreamlitCallbackHandler(st.container(), expand_new_thoughts=True)
55
+ response = search_agent.run(st.session_state.messages, callbacks=[st_callback])
56
+ st.write(response)
57
+ st.session_state.messages.append({"role": "assistant", "content": response})
58
+ except Exception as e:
59
+ st.error(f"An error occurred: {e}")
60
  else:
61
+ st.info("Please enter your Groq API key in the sidebar to proceed.")