Merge pull request #12604 from maurerle/ddg_improve_stacktrace
Some checks are pending
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Python CI / Format Backend (3.11.x) (push) Waiting to run
Python CI / Format Backend (3.12.x) (push) Waiting to run
Frontend Build / Format & Build Frontend (push) Waiting to run
Frontend Build / Frontend Unit Tests (push) Waiting to run

**fix** improve stack trace of duckduckgo exception
This commit is contained in:
Tim Jaeryang Baek 2025-04-08 13:03:57 -07:00 committed by GitHub
commit 2575dac4ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 10 deletions

View File

@ -3,6 +3,7 @@ from typing import Optional
from open_webui.retrieval.web.main import SearchResult, get_filtered_results from open_webui.retrieval.web.main import SearchResult, get_filtered_results
from duckduckgo_search import DDGS from duckduckgo_search import DDGS
from duckduckgo_search.exceptions import RatelimitException
from open_webui.env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -22,16 +23,15 @@ def search_duckduckgo(
list[SearchResult]: A list of search results list[SearchResult]: A list of search results
""" """
# Use the DDGS context manager to create a DDGS object # Use the DDGS context manager to create a DDGS object
search_results = []
with DDGS() as ddgs: with DDGS() as ddgs:
# Use the ddgs.text() method to perform the search # Use the ddgs.text() method to perform the search
ddgs_gen = ddgs.text( try:
query, safesearch="moderate", max_results=count, backend="api" search_results = ddgs.text(
) query, safesearch="moderate", max_results=count, backend="lite"
# Check if there are search results )
if ddgs_gen: except RatelimitException as e:
# Convert the search results into a list log.error(f"RatelimitException: {e}")
search_results = [r for r in ddgs_gen]
if filter_list: if filter_list:
search_results = get_filtered_results(search_results, filter_list) search_results = get_filtered_results(search_results, filter_list)

View File

@ -98,7 +98,7 @@ pytube==15.0.0
extract_msg extract_msg
pydub pydub
duckduckgo-search~=7.3.2 duckduckgo-search~=7.5.5
## Google Drive ## Google Drive
google-api-python-client google-api-python-client

View File

@ -104,7 +104,7 @@ dependencies = [
"extract_msg", "extract_msg",
"pydub", "pydub",
"duckduckgo-search~=7.3.2", "duckduckgo-search~=7.5.5",
"google-api-python-client", "google-api-python-client",
"google-auth-httplib2", "google-auth-httplib2",