Unverified Commit 7d2ad8c4 authored by Que Nguyen's avatar Que Nguyen Committed by GitHub
Browse files

Set filter_list as optional param in duckduckgo.py

parent a02139ba
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__) ...@@ -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 ...@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment