Shreyas094
commited on
Commit
•
218de65
1
Parent(s):
a7317eb
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ import torch
|
|
15 |
from datetime import datetime
|
16 |
import os
|
17 |
from dotenv import load_dotenv
|
|
|
18 |
|
19 |
# Load environment variables from a .env file
|
20 |
load_dotenv()
|
@@ -40,8 +41,8 @@ similarity_model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
40 |
|
41 |
# Set up a session with retry mechanism
|
42 |
def requests_retry_session(
|
43 |
-
retries=
|
44 |
-
backoff_factor=0.
|
45 |
status_forcelist=(500, 502, 504),
|
46 |
session=None,
|
47 |
):
|
@@ -339,17 +340,20 @@ def search_and_scrape(query, chat_history, num_results=5, scraper="trafilatura",
|
|
339 |
'Sec-Fetch-Site': 'same-origin',
|
340 |
}
|
341 |
|
342 |
-
|
343 |
# Send request to SearXNG
|
344 |
logger.info(f"Sending request to SearXNG for query: {rephrased_query}")
|
345 |
session = requests_retry_session()
|
346 |
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
|
|
|
|
|
|
|
|
353 |
|
354 |
search_results = response.json()
|
355 |
logger.debug(f"SearXNG Response: {search_results}")
|
@@ -439,12 +443,9 @@ def search_and_scrape(query, chat_history, num_results=5, scraper="trafilatura",
|
|
439 |
|
440 |
return llm_summary
|
441 |
|
442 |
-
except requests.exceptions.RequestException as e:
|
443 |
-
logger.error(f"Request exception: {e}")
|
444 |
-
return f"An error occurred during the search: {e}"
|
445 |
except Exception as e:
|
446 |
-
logger.error(f"Unexpected error: {e}")
|
447 |
-
return f"An unexpected error occurred: {e}"
|
448 |
|
449 |
|
450 |
def chat_function(message, history, num_results, scraper, max_chars, time_range, language, category, engines, safesearch, method, llm_temperature):
|
|
|
15 |
from datetime import datetime
|
16 |
import os
|
17 |
from dotenv import load_dotenv
|
18 |
+
import certifi
|
19 |
|
20 |
# Load environment variables from a .env file
|
21 |
load_dotenv()
|
|
|
41 |
|
42 |
# Set up a session with retry mechanism
|
43 |
def requests_retry_session(
|
44 |
+
retries=3,
|
45 |
+
backoff_factor=0.3,
|
46 |
status_forcelist=(500, 502, 504),
|
47 |
session=None,
|
48 |
):
|
|
|
340 |
'Sec-Fetch-Site': 'same-origin',
|
341 |
}
|
342 |
|
|
|
343 |
# Send request to SearXNG
|
344 |
logger.info(f"Sending request to SearXNG for query: {rephrased_query}")
|
345 |
session = requests_retry_session()
|
346 |
|
347 |
+
try:
|
348 |
+
if method.upper() == "GET":
|
349 |
+
response = session.get(SEARXNG_URL, params=params, headers=headers, timeout=10, verify=certifi.where())
|
350 |
+
else: # POST
|
351 |
+
response = session.post(SEARXNG_URL, data=params, headers=headers, timeout=10, verify=certifi.where())
|
352 |
+
|
353 |
+
response.raise_for_status()
|
354 |
+
except requests.exceptions.RequestException as e:
|
355 |
+
logger.error(f"Error during SearXNG request: {e}")
|
356 |
+
return f"An error occurred during the search request: {e}"
|
357 |
|
358 |
search_results = response.json()
|
359 |
logger.debug(f"SearXNG Response: {search_results}")
|
|
|
443 |
|
444 |
return llm_summary
|
445 |
|
|
|
|
|
|
|
446 |
except Exception as e:
|
447 |
+
logger.error(f"Unexpected error in search_and_scrape: {e}")
|
448 |
+
return f"An unexpected error occurred during the search and scrape process: {e}"
|
449 |
|
450 |
|
451 |
def chat_function(message, history, num_results, scraper, max_chars, time_range, language, category, engines, safesearch, method, llm_temperature):
|