aasherkamal216 commited on
Commit
8081af7
·
unverified ·
1 Parent(s): c0f0b4a

Add files via upload

Browse files
Files changed (2) hide show
  1. 18-tools_agent_app.py +50 -0
  2. requirements.txt +36 -0
18-tools_agent_app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, dotenv
2
+ dotenv.load_dotenv()
3
+ import streamlit as st
4
+ from langchain_groq import ChatGroq
5
+ from langchain_community.utilities import ArxivAPIWrapper, WikipediaAPIWrapper
6
+ from langchain_community.tools import ArxivQueryRun, WikipediaQueryRun, DuckDuckGoSearchRun
7
+ from langchain.agents import initialize_agent, AgentType
8
+ from langchain.callbacks import StreamlitCallbackHandler
9
+
10
+ # Wikipedia Tool
11
+ wiki_wrapper = WikipediaAPIWrapper(top_k_results=1, doc_content_chars_max=300)
12
+ wiki_tool = WikipediaQueryRun(api_wrapper=wiki_wrapper)
13
+ # Arxiv Tool
14
+ arxiv_wrapper = ArxivAPIWrapper(top_k_results=1, doc_content_chars_max=300)
15
+ arxiv_tool = ArxivQueryRun(api_wrapper=arxiv_wrapper)
16
+ # DuckDuckGo Search Tool
17
+ search = DuckDuckGoSearchRun(name="Internet Search")
18
+
19
+ # Streamlit Code
20
+ 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"] = [
28
+ {"role": "assistant", "content": "Hi there! How can I help you today?"}
29
+ ]
30
+
31
+ for message in st.session_state.messages:
32
+ st.chat_message(message['role']).write(message['content'])
33
+
34
+ if api_key:
35
+ if prompt := st.chat_input("What is Generative AI?"):
36
+ st.session_state.messages.append({"role": "user", "content": prompt})
37
+ st.chat_message("user").write(prompt)
38
+
39
+ llm = ChatGroq(model="llama-3.1-70b-versatile", api_key=api_key, streaming=True)
40
+ tools = [wiki_tool, arxiv_tool, search]
41
+
42
+ search_agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, handling_parsing_errors=True)
43
+
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")
requirements.txt ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain
2
+ python-dotenv
3
+ langchain_community
4
+ pypdf
5
+ bs4
6
+ arxiv
7
+ pymupdf
8
+ wikipedia
9
+ langchain-text-splitters
10
+ lxml
11
+ requests
12
+ langchain-google-genai
13
+ google-generativeai
14
+ langchain-cohere
15
+ sentence-transformers
16
+ langchain-huggingface
17
+ langchain-chroma
18
+ chromadb
19
+ faiss-cpu
20
+ langchain-qdrant
21
+ qrant_client
22
+ streamlit
23
+ langchain-groq
24
+ fastapi
25
+ uvicorn
26
+ langserve
27
+ arxiv
28
+ wikipedia
29
+ langchainhub
30
+ duckduckgo-search
31
+ psycopg2
32
+ youtube_transcript_api
33
+ unstructured
34
+ pytube
35
+ numexpr
36
+ huggingface_hub