Set filter_list as optional param in duckduckgo.py

This commit is contained in:
Que Nguyen 2024-06-17 14:34:59 +07:00 committed by GitHub
parent a02139ba9d
commit 7d2ad8c4bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,6 @@
import logging import logging
from typing import List from typing import List, Optional
from apps.rag.search.main import SearchResult, filter_by_whitelist from apps.rag.search.main import SearchResult, get_filtered_results
from duckduckgo_search import DDGS from duckduckgo_search import DDGS
from config import SRC_LOG_LEVELS from config import SRC_LOG_LEVELS
@ -8,7 +8,7 @@ log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])
def search_duckduckgo(query: str, count: int, whitelist:List[str]) -> list[SearchResult]: def search_duckduckgo(query: str, count: int, filter_list: Optional[List[str]] = None) -> list[SearchResult]:
""" """
Search using DuckDuckGo's Search API and return the results as a list of SearchResult objects. Search using DuckDuckGo's Search API and return the results as a list of SearchResult objects.
Args: Args:
@ -41,7 +41,7 @@ def search_duckduckgo(query: str, count: int, whitelist:List[str]) -> list[Searc
snippet=result.get("body"), snippet=result.get("body"),
) )
) )
# print(results) if filter_list:
filtered_results = filter_by_whitelist(results, whitelist) results = get_filtered_results(results, filter_list)
# Return the list of search results # Return the list of search results
return filtered_results return results