diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-01-26 07:54:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-26 07:54:13 +0100 |
commit | feb83c168b0a57ecd8c511aa654209c5f40da30e (patch) | |
tree | 84ef9a576064b7480e339426d9966b17a3102cad /g4f/gui/server/internet.py | |
parent | Merge pull request #1510 from hlohaus/sort (diff) | |
download | gpt4free-0.2.0.6.tar gpt4free-0.2.0.6.tar.gz gpt4free-0.2.0.6.tar.bz2 gpt4free-0.2.0.6.tar.lz gpt4free-0.2.0.6.tar.xz gpt4free-0.2.0.6.tar.zst gpt4free-0.2.0.6.zip |
Diffstat (limited to 'g4f/gui/server/internet.py')
-rw-r--r-- | g4f/gui/server/internet.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/g4f/gui/server/internet.py b/g4f/gui/server/internet.py index 6c2e3a89..a6bfc885 100644 --- a/g4f/gui/server/internet.py +++ b/g4f/gui/server/internet.py @@ -1,8 +1,14 @@ from __future__ import annotations -from bs4 import BeautifulSoup from aiohttp import ClientSession, ClientTimeout -from duckduckgo_search import DDGS +try: + from duckduckgo_search import DDGS + from bs4 import BeautifulSoup + has_requirements = True +except ImportError: + has_requirements = False +from ...errors import MissingRequirementsError + import asyncio class SearchResults(): @@ -88,6 +94,8 @@ async def fetch_and_scrape(session: ClientSession, url: str, max_words: int = No return async def search(query: str, n_results: int = 5, max_words: int = 2500, add_text: bool = True) -> SearchResults: + if not has_requirements: + raise MissingRequirementsError('Install "duckduckgo-search" and "beautifulsoup4" package') with DDGS() as ddgs: results = [] for result in ddgs.text( |