rainbowemoji commited on
Commit
acfe4e6
·
1 Parent(s): 7821cec

fix: type error for setting nul

Browse files
Files changed (2) hide show
  1. .idea/workspace.xml +0 -2
  2. app.py +17 -13
.idea/workspace.xml CHANGED
@@ -5,10 +5,8 @@
5
  </component>
6
  <component name="ChangeListManager">
7
  <list default="true" id="48e09a2c-c8fe-48db-8b61-cb395ec0aa52" name="Changes" comment="">
8
- <change beforePath="$PROJECT_DIR$/.idea/etf-assistant.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/etf-assistant.iml" afterDir="false" />
9
  <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
10
  <change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
11
- <change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
12
  </list>
13
  <option name="SHOW_DIALOG" value="false" />
14
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
 
5
  </component>
6
  <component name="ChangeListManager">
7
  <list default="true" id="48e09a2c-c8fe-48db-8b61-cb395ec0aa52" name="Changes" comment="">
 
8
  <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
9
  <change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
 
10
  </list>
11
  <option name="SHOW_DIALOG" value="false" />
12
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
app.py CHANGED
@@ -3,9 +3,9 @@ import pinecone
3
  import openai
4
 
5
  from langchain.embeddings.openai import OpenAIEmbeddings
6
- from langchain.text_splitter import CharacterTextSplitter
 
7
  from langchain.vectorstores import Pinecone
8
- from langchain.document_loaders import PyPDFLoader
9
  from langchain.chains import ConversationalRetrievalChain
10
  from langchain.chat_models import ChatOpenAI
11
  import streamlit as st
@@ -21,18 +21,23 @@ def _initialize_env():
21
 
22
 
23
  def _initialize_indexes():
24
- loader = PyPDFLoader("./etf-book.pdf")
25
- documents = loader.load()
26
- text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
27
- docs = text_splitter.split_documents(documents)
28
  embeddings = OpenAIEmbeddings()
29
 
30
- db = Pinecone.from_documents(
31
- docs,
32
- embeddings,
33
- index_name=st.secrets["pinecone_table_name"]
 
 
 
 
 
 
 
 
 
34
  )
35
- return db
36
 
37
 
38
  def _initialize_retriever(db_object):
@@ -50,13 +55,12 @@ chat_history = []
50
  def answer(user_input):
51
  if user_input == '':
52
  return
53
- print("----------", user_input)
54
  global chat_history
55
  result = qa({
56
  "question": user_input,
57
  "chat_history": chat_history
58
  })
59
- chat_history = chat_history.append((user_input, result["answer"]))
60
  chat_history = chat_history[-10:]
61
  st.write(
62
  "Bot: ",
 
3
  import openai
4
 
5
  from langchain.embeddings.openai import OpenAIEmbeddings
6
+ # from langchain.text_splitter import CharacterTextSplitter
7
+ # from langchain.document_loaders import PyPDFLoader
8
  from langchain.vectorstores import Pinecone
 
9
  from langchain.chains import ConversationalRetrievalChain
10
  from langchain.chat_models import ChatOpenAI
11
  import streamlit as st
 
21
 
22
 
23
  def _initialize_indexes():
 
 
 
 
24
  embeddings = OpenAIEmbeddings()
25
 
26
+ # loader = PyPDFLoader("./etf-book.pdf")
27
+ # documents = loader.load()
28
+ # text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
29
+ # docs = text_splitter.split_documents(documents)
30
+ # db = Pinecone.from_documents(
31
+ # docs,
32
+ # embeddings,
33
+ # index_name=st.secrets["pinecone_table_name"]
34
+ # )
35
+
36
+ db_object = Pinecone.from_existing_index(
37
+ st.secrets["pinecone_table_name"],
38
+ embeddings
39
  )
40
+ return db_object
41
 
42
 
43
  def _initialize_retriever(db_object):
 
55
  def answer(user_input):
56
  if user_input == '':
57
  return
 
58
  global chat_history
59
  result = qa({
60
  "question": user_input,
61
  "chat_history": chat_history
62
  })
63
+ chat_history.append((user_input, result["answer"]))
64
  chat_history = chat_history[-10:]
65
  st.write(
66
  "Bot: ",