Spaces:
Runtime error
Runtime error
Chintan Donda
commited on
Commit
•
c8e892f
1
Parent(s):
92e120c
Handling error in Custom query widget
Browse files- app.py +7 -3
- src/langchain_utils.py +4 -0
app.py
CHANGED
@@ -49,9 +49,13 @@ class DomState:
|
|
49 |
question=question,
|
50 |
question_category=question_category
|
51 |
)
|
52 |
-
if
|
53 |
-
|
54 |
-
self.relevant_paragraphs =
|
|
|
|
|
|
|
|
|
55 |
return self.relevant_paragraphs
|
56 |
|
57 |
|
|
|
49 |
question=question,
|
50 |
question_category=question_category
|
51 |
)
|
52 |
+
# Index may not be found if there are no data ingested for the given question_category. In that case, display the warning message.
|
53 |
+
if not self.relevant_paragraphs:
|
54 |
+
self.relevant_paragraphs = f'Index for {question_category} not found. That means no PDFs, Text files, or URLs have been ingested and indexed so far. Ingest the new data for {question_category} and then querying again.'
|
55 |
+
else:
|
56 |
+
if self.index_type in ['FAISS', 'Chroma']:
|
57 |
+
self.sources_relevant_paragraphs = [doc.metadata for doc in self.relevant_paragraphs]
|
58 |
+
self.relevant_paragraphs = [doc.page_content.replace('\n', '').replace('\t', ' ') for doc in self.relevant_paragraphs]
|
59 |
return self.relevant_paragraphs
|
60 |
|
61 |
|
src/langchain_utils.py
CHANGED
@@ -669,6 +669,10 @@ class LANGCHAIN_UTILS:
|
|
669 |
# Get the index of the given question_category
|
670 |
index = self.index_category_doc_type_wise_index[question_category][constants_utils.INDEX_CATEGORY_MASTER_INDEX_DOC_TYPE]
|
671 |
|
|
|
|
|
|
|
|
|
672 |
if self.index_type == 'FAISS':
|
673 |
response = index.similarity_search(
|
674 |
question,
|
|
|
669 |
# Get the index of the given question_category
|
670 |
index = self.index_category_doc_type_wise_index[question_category][constants_utils.INDEX_CATEGORY_MASTER_INDEX_DOC_TYPE]
|
671 |
|
672 |
+
if not index:
|
673 |
+
logger.error(f'Index for {question_category} not found! That means no PDFs, Text files, or URLs have been ingested and indexed so far. Ingest the new data for {question_category} and then querying again.')
|
674 |
+
return response
|
675 |
+
|
676 |
if self.index_type == 'FAISS':
|
677 |
response = index.similarity_search(
|
678 |
question,
|