Spaces:
Runtime error
Runtime error
Hard-coded condition for date outside range and increase in the step size for the search.
Browse files- public_app.py +8 -4
public_app.py
CHANGED
@@ -54,14 +54,18 @@ def get_chain(query, api_key=os.environ['OPENAI_API_KEY']):
|
|
54 |
logging.info('Extracting the date in numeric format..')
|
55 |
date_response = date_extractor.run(query)
|
56 |
if date_response == 'False':
|
57 |
-
logging.info(
|
|
|
58 |
return 'No date elements found. Please include temporal references in your query. ' \
|
59 |
'If you believe this is wrong, please flag below as appropriate.'
|
60 |
else:
|
61 |
filter_date = json.loads(date_response)
|
62 |
logging.info(f'Date parameters retrieved: {filter_date}')
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
65 |
logging.info(20 * '-' + 'Metadata for the documents to be used' + 20 * '-')
|
66 |
for doc in filtered_context:
|
67 |
logging.info(doc.metadata)
|
@@ -84,7 +88,7 @@ if __name__ == '__main__':
|
|
84 |
'hallucination. Nevertheless, the usual caveats for applications making use of generative AI apply.'
|
85 |
' Click the query examples below to see some possible outputs from the model.',
|
86 |
article='**Disclaimer**: This app is for demonstration purposes only, and no assurance of uninterrupted'
|
87 |
-
|
88 |
' time to complete '
|
89 |
'during periods of heavy usage. There is still significant work planned ahead. Please be patient :)',
|
90 |
analytics_enabled=True,
|
|
|
54 |
logging.info('Extracting the date in numeric format..')
|
55 |
date_response = date_extractor.run(query)
|
56 |
if date_response == 'False':
|
57 |
+
logging.info(
|
58 |
+
'No date elements found . Running the qa without filtering can output incorrect results.')
|
59 |
return 'No date elements found. Please include temporal references in your query. ' \
|
60 |
'If you believe this is wrong, please flag below as appropriate.'
|
61 |
else:
|
62 |
filter_date = json.loads(date_response)
|
63 |
logging.info(f'Date parameters retrieved: {filter_date}')
|
64 |
+
if (int(filter_date['year']) > 2023 and int(filter_date['month']) > 6) | (
|
65 |
+
int(filter_date['year']) < 1936 and int(filter_date['month']) < 3):
|
66 |
+
return 'Date is in the future or it is before the earliest of the publicly available records.' \
|
67 |
+
'If you believe this is wrong, please flag below as appropriate.'
|
68 |
+
filtered_context = search_with_filter(vs, query, init_k=200, step=500, target_k=7, filter_dict=filter_date)
|
69 |
logging.info(20 * '-' + 'Metadata for the documents to be used' + 20 * '-')
|
70 |
for doc in filtered_context:
|
71 |
logging.info(doc.metadata)
|
|
|
88 |
'hallucination. Nevertheless, the usual caveats for applications making use of generative AI apply.'
|
89 |
' Click the query examples below to see some possible outputs from the model.',
|
90 |
article='**Disclaimer**: This app is for demonstration purposes only, and no assurance of uninterrupted'
|
91 |
+
' functionality can be given at this time. Answers may take some'
|
92 |
' time to complete '
|
93 |
'during periods of heavy usage. There is still significant work planned ahead. Please be patient :)',
|
94 |
analytics_enabled=True,
|