andreped commited on
Commit
75bfa09
1 Parent(s): 08606a2

Added README instructions; refactored app

Browse files
Files changed (4) hide show
  1. README.md +17 -4
  2. app.py +8 -9
  3. requirements.txt +1 -0
  4. src/__init__.py +0 -0
README.md CHANGED
@@ -1,18 +1,31 @@
1
- # custom-chatbot-streamlit
2
 
3
  This application demonstrates how to setup a simple ChatBot with Azure OpenAI and StreamLit.
 
4
  The ChatBot enables you to talk with your own data - in this case, to learn about André's research.
5
 
6
  ## Getting Started
7
 
8
- 1.Setup virtual environment and install dependencies:
9
  ```
10
  python -m venv venv/
11
  source venv/bin/activate
12
  pip install -r requirements.txt
13
  ```
14
 
15
- 2. Download test data
 
 
 
 
 
 
 
 
16
 
17
- ##
 
 
 
18
 
 
 
1
+ # chatbot-streamlit-demo
2
 
3
  This application demonstrates how to setup a simple ChatBot with Azure OpenAI and StreamLit.
4
+
5
  The ChatBot enables you to talk with your own data - in this case, to learn about André's research.
6
 
7
  ## Getting Started
8
 
9
+ 1. Setup virtual environment and install dependencies:
10
  ```
11
  python -m venv venv/
12
  source venv/bin/activate
13
  pip install -r requirements.txt
14
  ```
15
 
16
+ 2. Set OPENAI_API_KEY:
17
+ ```
18
+ export OPENAI_API_KEY=<insert key here>
19
+ ```
20
+
21
+ 3. Download test data:
22
+ ```
23
+ gdown https://drive.google.com/drive/folders/1uDSAWtLvp1YPzfXUsK_v6DeWta16pq6y -O ./data/ --folder
24
+ ```
25
 
26
+ 3. Launch the app:
27
+ ```
28
+ streamlit run app.py
29
+ ```
30
 
31
+ You can then access the app in your browser at `http://localhost:8501`
app.py CHANGED
@@ -7,10 +7,6 @@ import os
7
  from llama_index import SimpleDirectoryReader
8
 
9
 
10
- # Load config values
11
- with open(r'config.json') as config_file:
12
- config_details = json.load(config_file)
13
-
14
  # Initialize message history
15
  st.header("Chat with André's research 💬 📚")
16
 
@@ -19,25 +15,29 @@ if "messages" not in st.session_state.keys(): # Initialize the chat message hist
19
  {"role": "assistant", "content": "Ask me a question about André's research!"}
20
  ]
21
 
 
 
 
 
22
 
23
  @st.cache_resource(show_spinner=False)
24
  def load_data():
25
- with st.spinner(text="Loading and indexing the Streamlit docs – hang tight! This should take 1-2 minutes."):
26
  documents = SimpleDirectoryReader(input_dir="./data", recursive=True).load_data()
27
  llm = AzureOpenAI(
28
  model="gpt-3.5-turbo",
29
- engine="chatbot-streamlit",
30
  temperature=0.5,
31
  api_key=os.getenv("OPENAI_API_KEY"),
32
  api_base=config_details['OPENAI_API_BASE'],
33
  api_type="azure",
34
  api_version=config_details['OPENAI_API_VERSION'],
35
- 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."
36
  )
37
  # You need to deploy your own embedding model as well as your own chat completion model
38
  embed_model = OpenAIEmbedding(
39
  model="text-embedding-ada-002",
40
- deployment_name="chatbot-streamlit-embedding",
41
  api_key=os.getenv("OPENAI_API_KEY"),
42
  api_base=config_details['OPENAI_API_BASE'],
43
  api_type="azure",
@@ -51,7 +51,6 @@ def load_data():
51
 
52
  def main():
53
  index = load_data()
54
-
55
  chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True)
56
 
57
  if prompt := st.chat_input("Your question"): # Prompt for user input and save to chat history
 
7
  from llama_index import SimpleDirectoryReader
8
 
9
 
 
 
 
 
10
  # Initialize message history
11
  st.header("Chat with André's research 💬 📚")
12
 
 
15
  {"role": "assistant", "content": "Ask me a question about André's research!"}
16
  ]
17
 
18
+ # Load config values
19
+ with open(r'config.json') as config_file:
20
+ config_details = json.load(config_file)
21
+
22
 
23
  @st.cache_resource(show_spinner=False)
24
  def load_data():
25
+ with st.spinner(text="Loading and indexing the provided dataset – hang tight! This may take a few seconds."):
26
  documents = SimpleDirectoryReader(input_dir="./data", recursive=True).load_data()
27
  llm = AzureOpenAI(
28
  model="gpt-3.5-turbo",
29
+ engine=config_details["ENGINE"],
30
  temperature=0.5,
31
  api_key=os.getenv("OPENAI_API_KEY"),
32
  api_base=config_details['OPENAI_API_BASE'],
33
  api_type="azure",
34
  api_version=config_details['OPENAI_API_VERSION'],
35
+ system_prompt="You are an expert on André's research and your job is to answer technical questions. Assume that all questions are related to André's research. Keep your answers technical and based on facts – do not hallucinate features."
36
  )
37
  # You need to deploy your own embedding model as well as your own chat completion model
38
  embed_model = OpenAIEmbedding(
39
  model="text-embedding-ada-002",
40
+ deployment_name=config_details["ENGINE_EMBEDDING"],
41
  api_key=os.getenv("OPENAI_API_KEY"),
42
  api_base=config_details['OPENAI_API_BASE'],
43
  api_type="azure",
 
51
 
52
  def main():
53
  index = load_data()
 
54
  chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True)
55
 
56
  if prompt := st.chat_input("Your question"): # Prompt for user input and save to chat history
requirements.txt CHANGED
@@ -3,3 +3,4 @@ openai
3
  llama-index
4
  nltk
5
  pypdf
 
 
3
  llama-index
4
  nltk
5
  pypdf
6
+ gdown
src/__init__.py DELETED
File without changes