eagle0504 commited on
Commit
39d3233
Β·
1 Parent(s): 746d2f1

app updated

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -1,12 +1,23 @@
1
- import streamlit as st
 
2
  import openai
 
 
3
  from llama_index.llms.openai import OpenAI
4
- from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
5
 
6
- st.set_page_config(page_title="Chat with the Streamlit docs, powered by LlamaIndex", page_icon="πŸ¦™", layout="centered", initial_sidebar_state="auto", menu_items=None)
7
- openai.api_key = st.secrets.openai_key
 
 
 
 
 
 
8
  st.title("Chat with the Streamlit docs, powered by LlamaIndex πŸ’¬πŸ¦™")
9
- st.info("Check out the full tutorial to build this app in our [blog post](https://blog.streamlit.io/build-a-chatbot-with-custom-data-sources-powered-by-llamaindex/)", icon="πŸ“ƒ")
 
 
 
10
 
11
  if "messages" not in st.session_state.keys(): # Initialize the chat messages history
12
  st.session_state.messages = [
@@ -16,6 +27,7 @@ if "messages" not in st.session_state.keys(): # Initialize the chat messages hi
16
  }
17
  ]
18
 
 
19
  @st.cache_resource(show_spinner=False)
20
  def load_data():
21
  reader = SimpleDirectoryReader(input_dir="./data", recursive=True)
@@ -58,4 +70,4 @@ if st.session_state.messages[-1]["role"] != "assistant":
58
  st.write_stream(response_stream.response_gen)
59
  message = {"role": "assistant", "content": response_stream.response}
60
  # Add response to message history
61
- st.session_state.messages.append(message)
 
1
+ import os
2
+
3
  import openai
4
+ import streamlit as st
5
+ from llama_index.core import Settings, SimpleDirectoryReader, VectorStoreIndex
6
  from llama_index.llms.openai import OpenAI
 
7
 
8
+ st.set_page_config(
9
+ page_title="Chat with the Streamlit docs, powered by LlamaIndex",
10
+ page_icon="πŸ¦™",
11
+ layout="centered",
12
+ initial_sidebar_state="auto",
13
+ menu_items=None,
14
+ )
15
+ openai.api_key = os.environ["OPENAI_API_KEY"]
16
  st.title("Chat with the Streamlit docs, powered by LlamaIndex πŸ’¬πŸ¦™")
17
+ st.info(
18
+ "Check out the full tutorial to build this app in our [blog post](https://blog.streamlit.io/build-a-chatbot-with-custom-data-sources-powered-by-llamaindex/)",
19
+ icon="πŸ“ƒ",
20
+ )
21
 
22
  if "messages" not in st.session_state.keys(): # Initialize the chat messages history
23
  st.session_state.messages = [
 
27
  }
28
  ]
29
 
30
+
31
  @st.cache_resource(show_spinner=False)
32
  def load_data():
33
  reader = SimpleDirectoryReader(input_dir="./data", recursive=True)
 
70
  st.write_stream(response_stream.response_gen)
71
  message = {"role": "assistant", "content": response_stream.response}
72
  # Add response to message history
73
+ st.session_state.messages.append(message)