|
import streamlit as st |
|
from langchain_core.messages import AIMessage, HumanMessage |
|
from langchain_community.document_loaders import WebBaseLoader |
|
|
|
|
|
def get_response(user_input): |
|
return "I dont know" |
|
|
|
def get_vector_store_from_url(url): |
|
loader = WebBaseLoader(url) |
|
documents = loader.load() |
|
return documents |
|
|
|
|
|
st.set_page_config(page_title= "Chat with Websites", page_icon="🤖") |
|
st.title("Chat with Websites") |
|
|
|
|
|
if "chat_history" not in st.session_state: |
|
st.session_state.chat_history = [ |
|
AIMessage(content = "Hello, I am a bot. How can I help you"), |
|
] |
|
|
|
|
|
|
|
with st.sidebar: |
|
st.header("Settings") |
|
website_url = st.text_input("Website URL") |
|
openai_apikey = st.text_input("Enter your OpenAI API key") |
|
|
|
if (website_url is None or website_url == "") or (openai_apikey is None or openai_apikey == ""): |
|
st.info("Please ensure if website URL and Open AI api key are entered") |
|
|
|
|
|
else: |
|
|
|
documents = get_vector_store_from_url(website_url) |
|
with st.sidebar: |
|
st.write(documents) |
|
|
|
|
|
user_query = st.chat_input("Type your message here...") |
|
if user_query is not None and user_query !="": |
|
response = get_response(user_query) |
|
st.session_state.chat_history .append(HumanMessage(content=user_query)) |
|
st.session_state.chat_history .append(AIMessageMessage(content=response)) |
|
|
|
|
|
|
|
for message in st.session_state.chat_history: |
|
if isinstance(message, AIMessage): |
|
with st.chat_message("AI"): |
|
st.write(message.content) |
|
elif isinstance(message, HumanMessage): |
|
with st.chat_message("Human"): |
|
st.write(message.content) |
|
|
|
|
|
|
|
|
|
|
|
|