yogjoshi14 commited on
Commit
011d448
1 Parent(s): 033b966

final changes

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -22,7 +22,7 @@ num_of_top_selection = 3
22
  CHUNK_SIZE = 500
23
  CHUNK_OVERLAP = 50
24
  embedding_dim = 768
25
-
26
  # Initialize Pinecone
27
  pc = pinecone.Pinecone(api_key=os.getenv("PINECONE_API_KEY"))
28
  index_name = "qp-ai-assessment"
@@ -40,11 +40,14 @@ def recreate_index():
40
  pc.create_index(
41
  name=index_name,
42
  metric='cosine',
43
- dimension=embedding_dim,
44
- spec=pinecone.PodSpec(os.getenv("PINECONE_ENV")) # 1536 dim of text-embedding-ada-002
45
  )
46
  print(f"Created new index: {index_name}")
47
 
 
 
 
48
  def get_text_from_pdf(pdf):
49
  pdf_reader = PdfReader(pdf)
50
  text = ""
@@ -108,6 +111,7 @@ def query_llm(retriever, query):
108
  llm=llm,
109
  retriever=retriever,
110
  return_source_documents=True,
 
111
  )
112
  result = qa_chain({'question': query, 'chat_history': st.session_state.messages})
113
  result = result['answer']
@@ -171,6 +175,5 @@ def boot():
171
 
172
  if __name__ == '__main__':
173
  #
174
- recreate_index()
175
  boot()
176
 
 
22
  CHUNK_SIZE = 500
23
  CHUNK_OVERLAP = 50
24
  embedding_dim = 768
25
+ reset_index = False
26
  # Initialize Pinecone
27
  pc = pinecone.Pinecone(api_key=os.getenv("PINECONE_API_KEY"))
28
  index_name = "qp-ai-assessment"
 
40
  pc.create_index(
41
  name=index_name,
42
  metric='cosine',
43
+ dimension=embedding_dim, # 1536 dim of text-embedding-ada-002
44
+ spec=pinecone.PodSpec(os.getenv("PINECONE_ENV"))
45
  )
46
  print(f"Created new index: {index_name}")
47
 
48
+ if reset_index:
49
+ recreate_index()
50
+
51
  def get_text_from_pdf(pdf):
52
  pdf_reader = PdfReader(pdf)
53
  text = ""
 
111
  llm=llm,
112
  retriever=retriever,
113
  return_source_documents=True,
114
+ response_if_no_docs_found= "I don't know"
115
  )
116
  result = qa_chain({'question': query, 'chat_history': st.session_state.messages})
117
  result = result['answer']
 
175
 
176
  if __name__ == '__main__':
177
  #
 
178
  boot()
179