feat: Add configurable DDGS backend selection with UI support (#20366)
* init * Update WebSearch.svelte * reorder
This commit is contained in:
@@ -3193,6 +3193,12 @@ SERPLY_API_KEY = PersistentConfig(
|
|||||||
os.getenv("SERPLY_API_KEY", ""),
|
os.getenv("SERPLY_API_KEY", ""),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
DDGS_BACKEND = PersistentConfig(
|
||||||
|
"DDGS_BACKEND",
|
||||||
|
"rag.web.search.ddgs_backend",
|
||||||
|
os.getenv("DDGS_BACKEND", "auto"),
|
||||||
|
)
|
||||||
|
|
||||||
JINA_API_KEY = PersistentConfig(
|
JINA_API_KEY = PersistentConfig(
|
||||||
"JINA_API_KEY",
|
"JINA_API_KEY",
|
||||||
"rag.web.search.jina_api_key",
|
"rag.web.search.jina_api_key",
|
||||||
|
|||||||
@@ -312,6 +312,7 @@ from open_webui.config import (
|
|||||||
YACY_PASSWORD,
|
YACY_PASSWORD,
|
||||||
SERPER_API_KEY,
|
SERPER_API_KEY,
|
||||||
SERPLY_API_KEY,
|
SERPLY_API_KEY,
|
||||||
|
DDGS_BACKEND,
|
||||||
SERPSTACK_API_KEY,
|
SERPSTACK_API_KEY,
|
||||||
SERPSTACK_HTTPS,
|
SERPSTACK_HTTPS,
|
||||||
TAVILY_API_KEY,
|
TAVILY_API_KEY,
|
||||||
@@ -969,6 +970,7 @@ app.state.config.SERPSTACK_API_KEY = SERPSTACK_API_KEY
|
|||||||
app.state.config.SERPSTACK_HTTPS = SERPSTACK_HTTPS
|
app.state.config.SERPSTACK_HTTPS = SERPSTACK_HTTPS
|
||||||
app.state.config.SERPER_API_KEY = SERPER_API_KEY
|
app.state.config.SERPER_API_KEY = SERPER_API_KEY
|
||||||
app.state.config.SERPLY_API_KEY = SERPLY_API_KEY
|
app.state.config.SERPLY_API_KEY = SERPLY_API_KEY
|
||||||
|
app.state.config.DDGS_BACKEND = DDGS_BACKEND
|
||||||
app.state.config.TAVILY_API_KEY = TAVILY_API_KEY
|
app.state.config.TAVILY_API_KEY = TAVILY_API_KEY
|
||||||
app.state.config.SEARCHAPI_API_KEY = SEARCHAPI_API_KEY
|
app.state.config.SEARCHAPI_API_KEY = SEARCHAPI_API_KEY
|
||||||
app.state.config.SEARCHAPI_ENGINE = SEARCHAPI_ENGINE
|
app.state.config.SEARCHAPI_ENGINE = SEARCHAPI_ENGINE
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ def search_duckduckgo(
|
|||||||
count: int,
|
count: int,
|
||||||
filter_list: Optional[list[str]] = None,
|
filter_list: Optional[list[str]] = None,
|
||||||
concurrent_requests: Optional[int] = None,
|
concurrent_requests: Optional[int] = None,
|
||||||
|
backend: Optional[str] = "auto",
|
||||||
) -> list[SearchResult]:
|
) -> 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:
|
||||||
query (str): The query to search for
|
query (str): The query to search for
|
||||||
count (int): The number of results to return
|
count (int): The number of results to return
|
||||||
|
backend (str): The search backend to use (auto, duckduckgo, google, brave, etc.)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[SearchResult]: A list of search results
|
list[SearchResult]: A list of search results
|
||||||
@@ -32,7 +34,7 @@ def search_duckduckgo(
|
|||||||
# Use the ddgs.text() method to perform the search
|
# Use the ddgs.text() method to perform the search
|
||||||
try:
|
try:
|
||||||
search_results = ddgs.text(
|
search_results = ddgs.text(
|
||||||
query, safesearch="moderate", max_results=count, backend="lite"
|
query, safesearch="moderate", max_results=count, backend=backend
|
||||||
)
|
)
|
||||||
except RatelimitException as e:
|
except RatelimitException as e:
|
||||||
log.error(f"RatelimitException: {e}")
|
log.error(f"RatelimitException: {e}")
|
||||||
|
|||||||
@@ -543,6 +543,7 @@ async def get_rag_config(request: Request, user=Depends(get_admin_user)):
|
|||||||
"SERPSTACK_HTTPS": request.app.state.config.SERPSTACK_HTTPS,
|
"SERPSTACK_HTTPS": request.app.state.config.SERPSTACK_HTTPS,
|
||||||
"SERPER_API_KEY": request.app.state.config.SERPER_API_KEY,
|
"SERPER_API_KEY": request.app.state.config.SERPER_API_KEY,
|
||||||
"SERPLY_API_KEY": request.app.state.config.SERPLY_API_KEY,
|
"SERPLY_API_KEY": request.app.state.config.SERPLY_API_KEY,
|
||||||
|
"DDGS_BACKEND": request.app.state.config.DDGS_BACKEND,
|
||||||
"TAVILY_API_KEY": request.app.state.config.TAVILY_API_KEY,
|
"TAVILY_API_KEY": request.app.state.config.TAVILY_API_KEY,
|
||||||
"SEARCHAPI_API_KEY": request.app.state.config.SEARCHAPI_API_KEY,
|
"SEARCHAPI_API_KEY": request.app.state.config.SEARCHAPI_API_KEY,
|
||||||
"SEARCHAPI_ENGINE": request.app.state.config.SEARCHAPI_ENGINE,
|
"SEARCHAPI_ENGINE": request.app.state.config.SEARCHAPI_ENGINE,
|
||||||
@@ -605,6 +606,7 @@ class WebConfig(BaseModel):
|
|||||||
SERPSTACK_HTTPS: Optional[bool] = None
|
SERPSTACK_HTTPS: Optional[bool] = None
|
||||||
SERPER_API_KEY: Optional[str] = None
|
SERPER_API_KEY: Optional[str] = None
|
||||||
SERPLY_API_KEY: Optional[str] = None
|
SERPLY_API_KEY: Optional[str] = None
|
||||||
|
DDGS_BACKEND: Optional[str] = None
|
||||||
TAVILY_API_KEY: Optional[str] = None
|
TAVILY_API_KEY: Optional[str] = None
|
||||||
SEARCHAPI_API_KEY: Optional[str] = None
|
SEARCHAPI_API_KEY: Optional[str] = None
|
||||||
SEARCHAPI_ENGINE: Optional[str] = None
|
SEARCHAPI_ENGINE: Optional[str] = None
|
||||||
@@ -1097,6 +1099,7 @@ async def update_rag_config(
|
|||||||
request.app.state.config.SERPSTACK_HTTPS = form_data.web.SERPSTACK_HTTPS
|
request.app.state.config.SERPSTACK_HTTPS = form_data.web.SERPSTACK_HTTPS
|
||||||
request.app.state.config.SERPER_API_KEY = form_data.web.SERPER_API_KEY
|
request.app.state.config.SERPER_API_KEY = form_data.web.SERPER_API_KEY
|
||||||
request.app.state.config.SERPLY_API_KEY = form_data.web.SERPLY_API_KEY
|
request.app.state.config.SERPLY_API_KEY = form_data.web.SERPLY_API_KEY
|
||||||
|
request.app.state.config.DDGS_BACKEND = form_data.web.DDGS_BACKEND
|
||||||
request.app.state.config.TAVILY_API_KEY = form_data.web.TAVILY_API_KEY
|
request.app.state.config.TAVILY_API_KEY = form_data.web.TAVILY_API_KEY
|
||||||
request.app.state.config.SEARCHAPI_API_KEY = form_data.web.SEARCHAPI_API_KEY
|
request.app.state.config.SEARCHAPI_API_KEY = form_data.web.SEARCHAPI_API_KEY
|
||||||
request.app.state.config.SEARCHAPI_ENGINE = form_data.web.SEARCHAPI_ENGINE
|
request.app.state.config.SEARCHAPI_ENGINE = form_data.web.SEARCHAPI_ENGINE
|
||||||
@@ -2071,6 +2074,7 @@ def search_web(
|
|||||||
request.app.state.config.WEB_SEARCH_RESULT_COUNT,
|
request.app.state.config.WEB_SEARCH_RESULT_COUNT,
|
||||||
request.app.state.config.WEB_SEARCH_DOMAIN_FILTER_LIST,
|
request.app.state.config.WEB_SEARCH_DOMAIN_FILTER_LIST,
|
||||||
concurrent_requests=request.app.state.config.WEB_SEARCH_CONCURRENT_REQUESTS,
|
concurrent_requests=request.app.state.config.WEB_SEARCH_CONCURRENT_REQUESTS,
|
||||||
|
backend=request.app.state.config.DDGS_BACKEND,
|
||||||
)
|
)
|
||||||
elif engine == "tavily":
|
elif engine == "tavily":
|
||||||
if request.app.state.config.TAVILY_API_KEY:
|
if request.app.state.config.TAVILY_API_KEY:
|
||||||
|
|||||||
@@ -697,7 +697,37 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if webConfig.WEB_SEARCH_ENGINE === 'duckduckgo'}
|
||||||
|
<div class="mb-2.5 flex w-full flex-col">
|
||||||
|
<div>
|
||||||
|
<div class=" self-center text-xs font-medium mb-1">
|
||||||
|
{$i18n.t('DDGS Backend')}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex w-full">
|
||||||
|
<div class="flex-1">
|
||||||
|
<select
|
||||||
|
class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
|
||||||
|
bind:value={webConfig.DDGS_BACKEND}
|
||||||
|
>
|
||||||
|
<option value="auto">{$i18n.t('Auto (Random)')}</option>
|
||||||
|
<option value="bing">{$i18n.t('Bing')}</option>
|
||||||
|
<option value="brave">{$i18n.t('Brave')}</option>
|
||||||
|
<option value="duckduckgo">{$i18n.t('DuckDuckGo')}</option>
|
||||||
|
<option value="google">{$i18n.t('Google')}</option>
|
||||||
|
<option value="grokipedia">{$i18n.t('Grokipedia')}</option>
|
||||||
|
<option value="mojeek">{$i18n.t('Mojeek')}</option>
|
||||||
|
<option value="wikipedia">{$i18n.t('Wikipedia')}</option>
|
||||||
|
<option value="yahoo">{$i18n.t('Yahoo')}</option>
|
||||||
|
<option value="yandex">{$i18n.t('Yandex')}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if webConfig.ENABLE_WEB_SEARCH}
|
{#if webConfig.ENABLE_WEB_SEARCH}
|
||||||
<div class="mb-2.5 flex w-full flex-col">
|
<div class="mb-2.5 flex w-full flex-col">
|
||||||
|
|||||||
Reference in New Issue
Block a user