BedfordD commited on
Commit
410b15d
Β·
1 Parent(s): 33f6d3a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from llama_index import VectorStoreIndex, ServiceContext, Document
3
+ from llama_index.llms import OpenAI
4
+ import openai
5
+ from llama_index import SimpleDirectoryReader
6
+
7
+ openai.api_key = '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'
8
+ st.header("Chat with the Streamlit docs πŸ’¬ πŸ“š")
9
+
10
+ if "messages" not in st.session_state.keys(): # Initialize the chat message history
11
+ st.session_state.messages = [
12
+ {"role": "assistant", "content": "Ask me a question about Streamlit's open-source Python library!"}
13
+ ]
14
+
15
+ @st.cache_resource(show_spinner=False)
16
+ def load_data():
17
+ with st.spinner(text="Loading and indexing the Streamlit docs – hang tight! This should take 1-2 minutes."):
18
+ reader = SimpleDirectoryReader(input_dir="./data", recursive=True)
19
+ docs = reader.load_data()
20
+ service_context = ServiceContext.from_defaults(llm=OpenAI(model="gpt-3.5-turbo", temperature=0.5, system_prompt="You are an expert on the Streamlit Python library and your job is to answer technical questions. Assume that all questions are related to the Streamlit Python library. Keep your answers technical and based on facts – do not hallucinate features."))
21
+ index = VectorStoreIndex.from_documents(docs, service_context=service_context)
22
+ return index
23
+
24
+ index = load_data()