File size: 1,353 Bytes
4c8c217
24b8963
1dd3a02
 
 
 
 
 
885ec28
b1d9a7f
 
885ec28
 
 
 
24b8963
 
4c8c217
1dd3a02
 
b0d0303
4c8c217
 
c46950c
6b80b65
6ad6f7e
1572555
24b8963
 
885ec28
 
1572555
d0e7841
6ad6f7e
 
 
 
 
 
 
 
 
 
 
 
6b80b65
4c8c217
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import streamlit as st
from langchain_core import AIMessage, HumanMessage


def get_response(user_input):
    return "I dont know"
    

# app config
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"),
]


#sidebar
with st.sidebar:
    st.header("Settings")
    website_url = st.text_input("Website URL")
    openai_apikey = st.text_input("Enter your OpenAI API key")

#user_input
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))
    
            
#conversation
for message in st.session_state.chat_history:
    if isinstance(message, AIMessage): # checking if the messsage is the instance of an AI message
        with st.chat_message("AI"):
            st.write(message.content)
    elif isinstance(message, HumanMessage): # checking if the messsage is the instance of a Human
        with st.chat_message("Human"):
            st.write(message.content)