Skip to content

Commit f850c60

Browse files
adding example of context aware chatbot, other minor ui improvements
1 parent 3090dfc commit f850c60

File tree

6 files changed

+51
-24
lines changed

6 files changed

+51
-24
lines changed

Home.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88

99
st.header("Chatbot Implementations with Langchain")
1010
st.write("""
11+
[![view source code ](https://img.shields.io/badge/GitHub%20Repository-gray?logo=github)](https://github.com/shashankdeshpande/langchain-chatbot)
12+
![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Flangchain-chatbot.streamlit.app&label=Visitors&labelColor=%235d5d5d&countColor=%231e7ebf&style=flat)
13+
""")
14+
st.write("""
1115
Langchain is a powerful framework designed to streamline the development of applications using Language Models (LLMs). It provides a comprehensive integration of various components, simplifying the process of assembling them to create robust applications.
1216
1317
Leveraging the power of Langchain, the creation of chatbots becomes effortless. Here are a few examples of chatbot implementations catering to different use cases:
1418
1519
- **Basic Chatbot**: Engage in interactive conversations with the LLM.
20+
- **Context aware chatbot**: A chatbot that remembers previous conversations and provides responses accordingly.
1621
- **Chatbot with Internet Access**: An internet-enabled chatbot capable of answering user queries about recent events.
1722
- **Chat with your documents** Empower the chatbot with the ability to access custom documents, enabling it to provide answers to user queries based on the referenced information.
1823
1924
To explore sample usage of each chatbot, please navigate to the corresponding chatbot section.
20-
21-
GitHub Repository: https://github.com/shashankdeshpande/langchain-chatbot
2225
""")

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Here are a few examples of chatbot implementations using Langchain and Streamlit
1010
- **Basic Chatbot** \
1111
Engage in interactive conversations with the LLM.
1212

13+
- **Context aware chatbot** \
14+
A chatbot that remembers previous conversations and provides responses accordingly.
15+
1316
- **Chatbot with Internet Access** \
1417
An internet-enabled chatbot capable of answering user queries about recent events.
1518

pages/1_💬_basic_chatbot.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
st.set_page_config(page_title="Chatbot", page_icon="💬")
99
st.header('Basic Chatbot')
1010
st.write('Allows users to interact with the LLM')
11-
with st.expander("Implementation details"):
12-
st.markdown("""
13-
- LLM - [OpenAI](https://python.langchain.com/docs/ecosystem/integrations/openai#llm)
14-
- Chain - [ConversationChain](https://github.com/hwchase17/langchain/blob/1d649b127eb10c426f9b9a67cbd1fe6ec8e6befa/langchain/chains/conversation/base.py#L12)
15-
""")
11+
st.write('[![view source code ](https://img.shields.io/badge/view_source_code-gray?logo=github)](https://github.com/shashankdeshpande/langchain-chatbot/blob/master/pages/1_%F0%9F%92%AC_basic_chatbot.py)')
1612

1713
class Basic:
1814

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import utils
2+
import streamlit as st
3+
from streaming import StreamHandler
4+
5+
from langchain.llms import OpenAI
6+
from langchain.chains import ConversationChain
7+
from langchain.memory import ConversationBufferMemory
8+
9+
st.set_page_config(page_title="Context aware chatbot", page_icon="⭐")
10+
st.header('Context aware chatbot')
11+
st.write('Enhancing Chatbot Interactions through Context Awareness')
12+
st.write('[![view source code ](https://img.shields.io/badge/view_source_code-gray?logo=github)](https://github.com/shashankdeshpande/langchain-chatbot/blob/master/pages/2_%E2%AD%90_context_aware_chatbot.py)')
13+
14+
class Basic:
15+
16+
def __init__(self):
17+
utils.configure_openai_api_key()
18+
self.openai_model = "gpt-3.5-turbo"
19+
20+
@st.cache_resource
21+
def setup_chain(_self):
22+
memory = ConversationBufferMemory()
23+
llm = OpenAI(model_name=_self.openai_model, temperature=0, streaming=True)
24+
chain = ConversationChain(llm=llm, memory=memory, verbose=True)
25+
return chain
26+
27+
@utils.enable_chat_history
28+
def main(self):
29+
chain = self.setup_chain()
30+
user_query = st.chat_input(placeholder="Ask me anything!")
31+
if user_query:
32+
utils.display_msg(user_query, 'user')
33+
with st.chat_message("assistant"):
34+
st_cb = StreamHandler(st.empty())
35+
response = chain.run(user_query, callbacks=[st_cb])
36+
st.session_state.messages.append({"role": "assistant", "content": response})
37+
38+
if __name__ == "__main__":
39+
obj = Basic()
40+
obj.main()

pages/2_🌐_chatbot_with_internet_access.py renamed to pages/3_🌐_chatbot_with_internet_access.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@
1010
st.set_page_config(page_title="ChatWeb", page_icon="🌐")
1111
st.header('Chatbot with Internet Access')
1212
st.write('Equipped with internet access, enables users to ask questions about recent events')
13-
with st.expander("Implementation details"):
14-
st.markdown("""
15-
- LLM - [OpenAI](https://python.langchain.com/docs/ecosystem/integrations/openai#llm)
16-
- Tools - [DuckDuckGoSearch](https://python.langchain.com/docs/modules/agents/tools/integrations/ddg)
17-
- Agent - [ReAct](https://python.langchain.com/docs/modules/agents/agent_types/react)
18-
""")
13+
st.write('[![view source code ](https://img.shields.io/badge/view_source_code-gray?logo=github)](https://github.com/shashankdeshpande/langchain-chatbot/blob/master/pages/3_%F0%9F%8C%90_chatbot_with_internet_access.py)')
1914

2015
class ChatbotTools:
2116

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@
1414
st.set_page_config(page_title="ChatPDF", page_icon="📄")
1515
st.header('Chat with your documents')
1616
st.write('Has access to custom documents and can respond to user queries by referring to the content within those documents')
17-
with st.expander("Implementation details"):
18-
st.markdown("""
19-
- LLM - [OpenAI](https://python.langchain.com/docs/ecosystem/integrations/openai#llm)
20-
- Document Loader - [PyPDFLoader](https://python.langchain.com/docs/modules/data_connection/document_loaders/how_to/pdf#using-pypdf)
21-
- Document Splitter - [RecursiveCharacterTextSplitter](https://python.langchain.com/docs/modules/data_connection/document_transformers/text_splitters/recursive_text_splitter)
22-
- Embeddings - [HuggingFaceEmbeddings](https://python.langchain.com/docs/modules/data_connection/text_embedding/integrations/huggingfacehub)
23-
- Vector store - [DocArrayInMemorySearch](https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/docarray_in_memory)
24-
- Document Retriever - [Vector store-backed retriever: Maximum Marginal Relevance](https://python.langchain.com/docs/modules/data_connection/retrievers/how_to/vectorstore#maximum-marginal-relevance-retrieval)
25-
- Memory - [ConversationBufferMemory](https://python.langchain.com/docs/modules/memory/how_to/buffer)
26-
- Chain - [ConversationalRetrievalChain](https://python.langchain.com/docs/modules/agents/agent_types/react)
27-
""")
17+
st.write('[![view source code ](https://img.shields.io/badge/view_source_code-gray?logo=github)](https://github.com/shashankdeshpande/langchain-chatbot/blob/master/pages/4_%F0%9F%93%84_chat_with_your_documents.py)')
2818

2919
class CustomDataChatbot:
3020

0 commit comments

Comments
 (0)