mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Only let agent use online search tool if connected to it
This commit is contained in:
@@ -15,7 +15,7 @@ from khoj.routers.helpers import (
|
|||||||
generate_online_subqueries,
|
generate_online_subqueries,
|
||||||
infer_webpage_urls,
|
infer_webpage_urls,
|
||||||
)
|
)
|
||||||
from khoj.utils.helpers import is_none_or_empty, timer
|
from khoj.utils.helpers import is_internet_connected, is_none_or_empty, timer
|
||||||
from khoj.utils.rawconfig import LocationData
|
from khoj.utils.rawconfig import LocationData
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -48,6 +48,9 @@ async def search_online(
|
|||||||
if not online_search_enabled():
|
if not online_search_enabled():
|
||||||
logger.warn("SERPER_DEV_API_KEY is not set")
|
logger.warn("SERPER_DEV_API_KEY is not set")
|
||||||
return {}
|
return {}
|
||||||
|
if not is_internet_connected():
|
||||||
|
logger.warn("Cannot search online as not connected to internet")
|
||||||
|
return {}
|
||||||
|
|
||||||
# Breakdown the query into subqueries to get the correct answer
|
# Breakdown the query into subqueries to get the correct answer
|
||||||
subqueries = await generate_online_subqueries(query, conversation_history, location)
|
subqueries = await generate_online_subqueries(query, conversation_history, location)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ from typing import TYPE_CHECKING, Optional, Union
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
import requests
|
||||||
import torch
|
import torch
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
from magika import Magika
|
from magika import Magika
|
||||||
@@ -397,3 +398,11 @@ def is_valid_url(url: str) -> bool:
|
|||||||
return all([result.scheme, result.netloc])
|
return all([result.scheme, result.netloc])
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def is_internet_connected():
|
||||||
|
try:
|
||||||
|
response = requests.head("https://www.google.com")
|
||||||
|
return response.status_code == 200
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user