Zenne commited on
Commit
154e3a2
1 Parent(s): fca61a3

added OPENAI_API_KEY

Browse files

llama_index GPTVectorStoreIndex uses LLM implicitly, so OPENAI_API_KEY is added

Files changed (4) hide show
  1. .vscode/settings.json +6 -0
  2. app.py +19 -16
  3. tmp_docs/1.txt +1 -0
  4. tmp_docs/2.txt +1 -0
.vscode/settings.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "[python]": {
3
+ "editor.defaultFormatter": "ms-python.autopep8"
4
+ },
5
+ "python.formatting.provider": "none"
6
+ }
app.py CHANGED
@@ -43,25 +43,28 @@ def query(index, query_text):
43
  return response
44
 
45
 
46
- # Initialize chatbot history
47
- chatbot = []
48
 
49
- # Display file upload component
50
- files = st.file_uploader('Upload Files', accept_multiple_files=True)
51
- if files is not None:
52
- save_file(files)
53
 
 
 
 
 
54
 
55
- index = ingest('tmp_docs')
56
 
57
- # Display message input component
58
- message = st.text_input('Enter message')
59
 
60
- # If message is entered, ingest documents and get chatbot response
61
- if message:
62
- chatbot.append(('You', message))
63
- chatbot += get_answer(index, message)
64
 
65
- # Display chat history
66
- st.text_area('Chatbot:', value='\n'.join(
67
- [f'{x[0]}: {x[1]}' for x in chatbot]), height=250)
 
43
  return response
44
 
45
 
46
+ os.environ['OPENAI_API_KEY'] = st.text_input(
47
+ "Enter your OpenAI API key", type="password")
48
 
49
+ if os.environ['OPENAI_API_KEY']:
50
+ # Initialize chatbot history
51
+ chatbot = []
 
52
 
53
+ # Display file upload component
54
+ files = st.file_uploader('Upload Files', accept_multiple_files=True)
55
+ if files is not None:
56
+ save_file(files)
57
 
58
+ index = ingest('tmp_docs')
59
 
60
+ # Display message input component
61
+ message = st.text_input('Enter message')
62
 
63
+ # If message is entered, ingest documents and get chatbot response
64
+ if message:
65
+ chatbot.append(('You', message))
66
+ chatbot += get_answer(index, message)
67
 
68
+ # Display chat history
69
+ st.text_area('Chatbot:', value='\n'.join(
70
+ [f'{x[0]}: {x[1]}' for x in chatbot]), height=250)
tmp_docs/1.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Bob says: 1+1=1
tmp_docs/2.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Carol says: 1+1=2