captain-awesome commited on
Commit
52b8278
1 Parent(s): 512154c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from langchain_core import AIMessage, HumanMessage
3
 
4
 
5
  def get_response(user_input):
@@ -23,22 +23,27 @@ with st.sidebar:
23
  website_url = st.text_input("Website URL")
24
  openai_apikey = st.text_input("Enter your OpenAI API key")
25
 
26
- #user_input
27
- user_query = st.chat_input("Type your message here...")
28
- if user_query is not None and user_query !="":
29
- response = get_response(user_query)
30
- st.session_state.chat_history .append(HumanMessage(content=user_query))
31
- st.session_state.chat_history .append(AIMessageMessage(content=response))
32
 
33
-
34
- #conversation
35
- for message in st.session_state.chat_history:
36
- if isinstance(message, AIMessage): # checking if the messsage is the instance of an AI message
37
- with st.chat_message("AI"):
38
- st.write(message.content)
39
- elif isinstance(message, HumanMessage): # checking if the messsage is the instance of a Human
40
- with st.chat_message("Human"):
41
- st.write(message.content)
 
 
 
 
 
 
 
 
 
42
 
43
 
44
 
 
1
  import streamlit as st
2
+ from langchain_core.messages import AIMessage, HumanMessage
3
 
4
 
5
  def get_response(user_input):
 
23
  website_url = st.text_input("Website URL")
24
  openai_apikey = st.text_input("Enter your OpenAI API key")
25
 
26
+ if (website_url is None or website_url == "") or (openai_apikey is None or openai_apikey == ""):
27
+ st.info("Please ensure if website URL and Open AI api key are entered")
 
 
 
 
28
 
29
+
30
+ else:
31
+ #user_input
32
+ user_query = st.chat_input("Type your message here...")
33
+ if user_query is not None and user_query !="":
34
+ response = get_response(user_query)
35
+ st.session_state.chat_history .append(HumanMessage(content=user_query))
36
+ st.session_state.chat_history .append(AIMessageMessage(content=response))
37
+
38
+
39
+ #conversation
40
+ for message in st.session_state.chat_history:
41
+ if isinstance(message, AIMessage): # checking if the messsage is the instance of an AI message
42
+ with st.chat_message("AI"):
43
+ st.write(message.content)
44
+ elif isinstance(message, HumanMessage): # checking if the messsage is the instance of a Human
45
+ with st.chat_message("Human"):
46
+ st.write(message.content)
47
 
48
 
49