Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -361,26 +361,25 @@ def extract_data(input_str):
|
|
| 361 |
|
| 362 |
def perform_search_and_get_results_histroy_filter(collection_name, query, reference,limit=6):
|
| 363 |
# Extract data from the reference
|
| 364 |
-
article_number, paragraph_number, characters = extract_data(reference)
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
return history_results
|
| 384 |
# Used function ends here :
|
| 385 |
@app.route('/history', methods=['OPTIONS'])
|
| 386 |
def historyOptions():
|
|
@@ -399,7 +398,6 @@ def history():
|
|
| 399 |
finale_result = []
|
| 400 |
if messages:
|
| 401 |
prompt = "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
| 402 |
-
|
| 403 |
search_results = perform_search_and_get_results('history', prompt)
|
| 404 |
for result in search_results:
|
| 405 |
history_answers = result.payload['reponse'].splite(',')
|
|
|
|
| 361 |
|
| 362 |
def perform_search_and_get_results_histroy_filter(collection_name, query, reference,limit=6):
|
| 363 |
# Extract data from the reference
|
| 364 |
+
article_number, paragraph_number, characters = extract_data(reference)
|
| 365 |
+
# Construct filters
|
| 366 |
+
filters = []
|
| 367 |
+
if article_number:
|
| 368 |
+
filters.append(models.FieldCondition(key="article", match=models.MatchValue(value=article_number+'a')))
|
| 369 |
+
if paragraph_number:
|
| 370 |
+
filters.append(models.FieldCondition(key="paragraph", match=models.MatchValue(value=paragraph_number+'a')))
|
| 371 |
+
if characters:
|
| 372 |
+
filters.append(models.FieldCondition(key="characters", match=models.MatchValue(value=characters+'a')))
|
| 373 |
+
|
| 374 |
+
# Perform the search
|
| 375 |
+
history_results = client.search(
|
| 376 |
+
collection_name=collection_name,
|
| 377 |
+
query_filter=models.Filter(should=filters),
|
| 378 |
+
query_vector=model.encode(query).tolist(),
|
| 379 |
+
limit=1
|
| 380 |
+
)
|
| 381 |
+
|
| 382 |
+
return history_results
|
|
|
|
| 383 |
# Used function ends here :
|
| 384 |
@app.route('/history', methods=['OPTIONS'])
|
| 385 |
def historyOptions():
|
|
|
|
| 398 |
finale_result = []
|
| 399 |
if messages:
|
| 400 |
prompt = "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
|
|
|
| 401 |
search_results = perform_search_and_get_results('history', prompt)
|
| 402 |
for result in search_results:
|
| 403 |
history_answers = result.payload['reponse'].splite(',')
|