Jeyanthi726 commited on
Commit
01168de
·
unverified ·
1 Parent(s): e3ccd7d

Added Required Files

Browse files
Files changed (3) hide show
  1. README.md +9 -1
  2. app.py +54 -0
  3. requirements.txt +32 -0
README.md CHANGED
@@ -1 +1,9 @@
1
- # Search-Engine-LLM
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ title: Search Engine
4
+ sdk: streamlit
5
+ emoji: 🏃
6
+ colorFrom: red
7
+ colorTo: yellow
8
+ short_description: Search Engine With LLM
9
+ ---
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain_groq import ChatGroq
3
+ from langchain_community.utilities import ArxivAPIWrapper,WikipediaAPIWrapper
4
+ from langchain_community.tools import ArxivQueryRun,WikipediaQueryRun,DuckDuckGoSearchRun
5
+ from langchain.agents import initialize_agent,AgentType
6
+ from langchain.callbacks import StreamlitCallbackHandler
7
+ import os
8
+ from dotenv import load_dotenv
9
+ ## Code
10
+ ####
11
+
12
+ ## Arxiv and wikipedia Tools
13
+ arxiv_wrapper=ArxivAPIWrapper(top_k_results=1, doc_content_chars_max=200)
14
+ arxiv=ArxivQueryRun(api_wrapper=arxiv_wrapper)
15
+
16
+ api_wrapper=WikipediaAPIWrapper(top_k_results=1,doc_content_chars_max=200)
17
+ wiki=WikipediaQueryRun(api_wrapper=api_wrapper)
18
+
19
+ search=DuckDuckGoSearchRun(name="Search")
20
+
21
+
22
+ st.title("🔎 LangChain - Chat with search")
23
+ """
24
+ In this example, we're using `StreamlitCallbackHandler` to display the thoughts and actions of an agent in an interactive Streamlit app.
25
+ Try more LangChain 🤝 Streamlit Agent examples at [github.com/langchain-ai/streamlit-agent](https://github.com/langchain-ai/streamlit-agent).
26
+ """
27
+
28
+ ## Sidebar for settings
29
+ st.sidebar.title("Settings")
30
+ api_key=st.sidebar.text_input("Enter your Groq API Key:",type="password")
31
+
32
+ if "messages" not in st.session_state:
33
+ st.session_state["messages"]=[
34
+ {"role":"assisstant","content":"Hi,I'm a chatbot who can search the web. How can I help you?"}
35
+ ]
36
+
37
+ for msg in st.session_state.messages:
38
+ st.chat_message(msg["role"]).write(msg['content'])
39
+
40
+ if prompt:=st.chat_input(placeholder="What is machine learning?"):
41
+ st.session_state.messages.append({"role":"user","content":prompt})
42
+ st.chat_message("user").write(prompt)
43
+
44
+ llm=ChatGroq(groq_api_key=api_key,model_name="Llama3-8b-8192",streaming=True)
45
+ tools=[search,arxiv,wiki]
46
+
47
+ search_agent=initialize_agent(tools,llm,agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,handling_parsing_errors=True)
48
+
49
+ with st.chat_message("assistant"):
50
+ st_cb=StreamlitCallbackHandler(st.container(),expand_new_thoughts=False)
51
+ response=search_agent.run(st.session_state.messages,callbacks=[st_cb])
52
+ st.session_state.messages.append({'role':'assistant',"content":response})
53
+ st.write(response)
54
+
requirements.txt ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain
2
+ python-dotenv
3
+ ipykernel
4
+ langchain-community
5
+ pypdf
6
+ bs4
7
+ arxiv
8
+ pymupdf
9
+ wikipedia
10
+ langchain-text-splitters
11
+ langchain-openai
12
+ chromadb
13
+ sentence_transformers
14
+ langchain_huggingface
15
+ faiss-cpu
16
+ langchain_chroma
17
+ duckdb
18
+ pandas
19
+ openai
20
+ langchain-groq
21
+ duckduckgo_search==5.3.1b1
22
+ pymupdf
23
+ arxiv
24
+ wikipedia
25
+ mysql-connector-python
26
+ SQLAlchemy
27
+ validators==0.28.1
28
+ youtube_transcript_api
29
+ unstructured
30
+ pytube
31
+ numexpr
32
+ huggingface_hub