From b1d83fc42cb608dd3baddeabaf584f8179c91b71 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 17 Jun 2024 14:32:23 -0700 Subject: [PATCH] chore: format --- backend/apps/rag/main.py | 16 ++++++++++------ backend/apps/rag/search/brave.py | 6 ++++-- backend/apps/rag/search/duckduckgo.py | 4 +++- backend/apps/rag/search/google_pse.py | 6 +++++- backend/apps/rag/search/main.py | 1 + backend/apps/rag/search/searxng.py | 6 +++++- backend/apps/rag/search/serper.py | 4 +++- backend/apps/rag/search/serpstack.py | 6 +++++- backend/config.py | 6 +++--- src/lib/i18n/locales/ko-KR/translation.json | 2 +- 10 files changed, 40 insertions(+), 17 deletions(-) diff --git a/backend/apps/rag/main.py b/backend/apps/rag/main.py index a47874f22..49146a215 100644 --- a/backend/apps/rag/main.py +++ b/backend/apps/rag/main.py @@ -777,7 +777,7 @@ def search_web(engine: str, query: str) -> list[SearchResult]: app.state.config.SEARXNG_QUERY_URL, query, app.state.config.RAG_WEB_SEARCH_RESULT_COUNT, - app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST + app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST, ) else: raise Exception("No SEARXNG_QUERY_URL found in environment variables") @@ -791,7 +791,7 @@ def search_web(engine: str, query: str) -> list[SearchResult]: app.state.config.GOOGLE_PSE_ENGINE_ID, query, app.state.config.RAG_WEB_SEARCH_RESULT_COUNT, - app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST + app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST, ) else: raise Exception( @@ -803,7 +803,7 @@ def search_web(engine: str, query: str) -> list[SearchResult]: app.state.config.BRAVE_SEARCH_API_KEY, query, app.state.config.RAG_WEB_SEARCH_RESULT_COUNT, - app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST + app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST, ) else: raise Exception("No BRAVE_SEARCH_API_KEY found in environment variables") @@ -824,7 +824,7 @@ def search_web(engine: str, query: str) -> list[SearchResult]: app.state.config.SERPER_API_KEY, query, app.state.config.RAG_WEB_SEARCH_RESULT_COUNT, - app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST + app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST, ) else: raise Exception("No SERPER_API_KEY found in environment variables") @@ -834,12 +834,16 @@ def search_web(engine: str, query: str) -> list[SearchResult]: app.state.config.SERPLY_API_KEY, query, app.state.config.RAG_WEB_SEARCH_RESULT_COUNT, - app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST + app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST, ) else: raise Exception("No SERPLY_API_KEY found in environment variables") elif engine == "duckduckgo": - return search_duckduckgo(query, app.state.config.RAG_WEB_SEARCH_RESULT_COUNT, app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST) + return search_duckduckgo( + query, + app.state.config.RAG_WEB_SEARCH_RESULT_COUNT, + app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST, + ) elif engine == "tavily": if app.state.config.TAVILY_API_KEY: return search_tavily( diff --git a/backend/apps/rag/search/brave.py b/backend/apps/rag/search/brave.py index a20a2cde8..76ad1fb47 100644 --- a/backend/apps/rag/search/brave.py +++ b/backend/apps/rag/search/brave.py @@ -9,7 +9,9 @@ log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) -def search_brave(api_key: str, query: str, count: int, filter_list: Optional[List[str]] = None) -> list[SearchResult]: +def search_brave( + api_key: str, query: str, count: int, filter_list: Optional[List[str]] = None +) -> list[SearchResult]: """Search using Brave's Search API and return the results as a list of SearchResult objects. Args: @@ -31,7 +33,7 @@ def search_brave(api_key: str, query: str, count: int, filter_list: Optional[Lis results = json_response.get("web", {}).get("results", []) if filter_list: results = get_filtered_results(results, filter_list) - + return [ SearchResult( link=result["url"], title=result.get("title"), snippet=result.get("snippet") diff --git a/backend/apps/rag/search/duckduckgo.py b/backend/apps/rag/search/duckduckgo.py index 8bcb18cc9..f0cc2a710 100644 --- a/backend/apps/rag/search/duckduckgo.py +++ b/backend/apps/rag/search/duckduckgo.py @@ -8,7 +8,9 @@ log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) -def search_duckduckgo(query: str, count: int, filter_list: Optional[List[str]] = None) -> 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. Args: diff --git a/backend/apps/rag/search/google_pse.py b/backend/apps/rag/search/google_pse.py index 84ecafa81..0c78512e7 100644 --- a/backend/apps/rag/search/google_pse.py +++ b/backend/apps/rag/search/google_pse.py @@ -11,7 +11,11 @@ log.setLevel(SRC_LOG_LEVELS["RAG"]) def search_google_pse( - api_key: str, search_engine_id: str, query: str, count: int, filter_list: Optional[List[str]] = None + api_key: str, + search_engine_id: str, + query: str, + count: int, + filter_list: Optional[List[str]] = None, ) -> list[SearchResult]: """Search using Google's Programmable Search Engine API and return the results as a list of SearchResult objects. diff --git a/backend/apps/rag/search/main.py b/backend/apps/rag/search/main.py index 4041372f3..49056f1fd 100644 --- a/backend/apps/rag/search/main.py +++ b/backend/apps/rag/search/main.py @@ -13,6 +13,7 @@ def get_filtered_results(results, filter_list): filtered_results.append(result) return filtered_results + class SearchResult(BaseModel): link: str title: Optional[str] diff --git a/backend/apps/rag/search/searxng.py b/backend/apps/rag/search/searxng.py index 850513ee1..f0e4a16ee 100644 --- a/backend/apps/rag/search/searxng.py +++ b/backend/apps/rag/search/searxng.py @@ -11,7 +11,11 @@ log.setLevel(SRC_LOG_LEVELS["RAG"]) def search_searxng( - query_url: str, query: str, count: int, filter_list: Optional[List[str]] = None, **kwargs + query_url: str, + query: str, + count: int, + filter_list: Optional[List[str]] = None, + **kwargs, ) -> List[SearchResult]: """ Search a SearXNG instance for a given query and return the results as a list of SearchResult objects. diff --git a/backend/apps/rag/search/serper.py b/backend/apps/rag/search/serper.py index 1e3918446..b278a4df1 100644 --- a/backend/apps/rag/search/serper.py +++ b/backend/apps/rag/search/serper.py @@ -10,7 +10,9 @@ log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) -def search_serper(api_key: str, query: str, count: int, filter_list: Optional[List[str]] = None) -> list[SearchResult]: +def search_serper( + api_key: str, query: str, count: int, filter_list: Optional[List[str]] = None +) -> list[SearchResult]: """Search using serper.dev's API and return the results as a list of SearchResult objects. Args: diff --git a/backend/apps/rag/search/serpstack.py b/backend/apps/rag/search/serpstack.py index f69baaf92..64b0f117d 100644 --- a/backend/apps/rag/search/serpstack.py +++ b/backend/apps/rag/search/serpstack.py @@ -11,7 +11,11 @@ log.setLevel(SRC_LOG_LEVELS["RAG"]) def search_serpstack( - api_key: str, query: str, count: int, filter_list: Optional[List[str]] = None, https_enabled: bool = True + api_key: str, + query: str, + count: int, + filter_list: Optional[List[str]] = None, + https_enabled: bool = True, ) -> list[SearchResult]: """Search using serpstack.com's and return the results as a list of SearchResult objects. diff --git a/backend/config.py b/backend/config.py index 5981debb0..01ce060a3 100644 --- a/backend/config.py +++ b/backend/config.py @@ -903,14 +903,14 @@ RAG_WEB_SEARCH_ENGINE = PersistentConfig( os.getenv("RAG_WEB_SEARCH_ENGINE", ""), ) -# You can provide a list of your own websites to filter after performing a web search. +# You can provide a list of your own websites to filter after performing a web search. # This ensures the highest level of safety and reliability of the information sources. RAG_WEB_SEARCH_DOMAIN_FILTER_LIST = PersistentConfig( "RAG_WEB_SEARCH_DOMAIN_FILTER_LIST", "rag.rag.web.search.domain.filter_list", [ - # "wikipedia.com", - # "wikimedia.org", + # "wikipedia.com", + # "wikimedia.org", # "wikidata.org", ], ) diff --git a/src/lib/i18n/locales/ko-KR/translation.json b/src/lib/i18n/locales/ko-KR/translation.json index 590c5f6ca..0ecb1a7f5 100644 --- a/src/lib/i18n/locales/ko-KR/translation.json +++ b/src/lib/i18n/locales/ko-KR/translation.json @@ -600,4 +600,4 @@ "Your account status is currently pending activation.": "현재 계정은 아직 활성화되지 않았습니다.", "Youtube": "유튜브", "Youtube Loader Settings": "유튜브 로더 설정" -} \ No newline at end of file +}