mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-28 05:27:35 +00:00
feat: add Olostep as a web search provider
This commit is contained in:
parent
5ea9ff3ed9
commit
39f2d35a63
4 changed files with 91 additions and 1 deletions
|
|
@ -1271,6 +1271,8 @@ SOUGOU_API_SK = os.getenv('SOUGOU_API_SK', '')
|
|||
|
||||
TAVILY_API_KEY = os.getenv('TAVILY_API_KEY', '')
|
||||
|
||||
OLOSTEP_API_KEY = os.getenv('OLOSTEP_API_KEY', '')
|
||||
|
||||
TAVILY_EXTRACT_DEPTH = os.getenv('TAVILY_EXTRACT_DEPTH', 'basic')
|
||||
|
||||
PLAYWRIGHT_WS_URL = os.getenv('PLAYWRIGHT_WS_URL', '')
|
||||
|
|
@ -2989,6 +2991,7 @@ DEFAULT_CONFIG = {
|
|||
'web.search.sougou_api_sid': SOUGOU_API_SID,
|
||||
'web.search.sougou_api_sk': SOUGOU_API_SK,
|
||||
'web.search.tavily_api_key': TAVILY_API_KEY,
|
||||
'web.search.olostep_api_key': OLOSTEP_API_KEY,
|
||||
'web.search.tavily_extract_depth': TAVILY_EXTRACT_DEPTH,
|
||||
'web.loader.playwright_ws_url': PLAYWRIGHT_WS_URL,
|
||||
'web.loader.playwright_timeout': PLAYWRIGHT_TIMEOUT,
|
||||
|
|
|
|||
59
backend/open_webui/retrieval/web/olostep.py
Normal file
59
backend/open_webui/retrieval/web/olostep.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
import requests
|
||||
from open_webui.retrieval.web.main import SearchResult, get_filtered_results
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
OLOSTEP_SEARCH_URL = "https://api.olostep.com/v1/searches"
|
||||
|
||||
|
||||
def search_olostep(
|
||||
api_key: str,
|
||||
query: str,
|
||||
count: int,
|
||||
filter_list: list[str] | None = None,
|
||||
) -> list[SearchResult]:
|
||||
"""Search using Olostep's Search API and return the results as a list of
|
||||
SearchResult objects.
|
||||
|
||||
Args:
|
||||
api_key (str): An Olostep API key
|
||||
query (str): The query to search for
|
||||
count (int): The maximum number of results to return
|
||||
filter_list (list[str] | None): Optional domain filter list
|
||||
|
||||
Returns:
|
||||
A list of SearchResult objects.
|
||||
"""
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
}
|
||||
data = {"query": query, "limit": count}
|
||||
|
||||
response = requests.post(
|
||||
OLOSTEP_SEARCH_URL,
|
||||
headers=headers,
|
||||
json=data,
|
||||
timeout=count * 3 + 10,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
json_response = response.json()
|
||||
|
||||
results = (json_response.get("result") or {}).get("links") or []
|
||||
if filter_list:
|
||||
results = get_filtered_results(results, filter_list)
|
||||
|
||||
return [
|
||||
SearchResult(
|
||||
link=result["url"],
|
||||
title=result.get("title", ""),
|
||||
snippet=result.get("description"),
|
||||
)
|
||||
for result in results[:count]
|
||||
if result.get("url")
|
||||
]
|
||||
|
|
@ -115,6 +115,7 @@ from open_webui.retrieval.web.serply import search_serply
|
|||
from open_webui.retrieval.web.serpstack import search_serpstack
|
||||
from open_webui.retrieval.web.sougou import search_sougou
|
||||
from open_webui.retrieval.web.tavily import search_tavily
|
||||
from open_webui.retrieval.web.olostep import search_olostep
|
||||
from open_webui.retrieval.web.utils import get_web_loader
|
||||
from open_webui.retrieval.web.yacy import search_yacy
|
||||
from open_webui.retrieval.web.yandex import search_yandex
|
||||
|
|
@ -384,6 +385,7 @@ RETRIEVAL_CONFIG_KEYS = {
|
|||
'SOUGOU_API_SID': 'web.search.sougou_api_sid',
|
||||
'SOUGOU_API_SK': 'web.search.sougou_api_sk',
|
||||
'TAVILY_API_KEY': 'web.search.tavily_api_key',
|
||||
'OLOSTEP_API_KEY': 'web.search.olostep_api_key',
|
||||
'TAVILY_EXTRACT_DEPTH': 'web.search.tavily_extract_depth',
|
||||
'TEXT_SPLITTER': 'rag.text_splitter',
|
||||
'TIKA_SERVER_URL': 'rag.tika_server_url',
|
||||
|
|
@ -2628,6 +2630,17 @@ async def search_web(request: Request, engine: str, query: str, user=None) -> li
|
|||
)
|
||||
else:
|
||||
raise Exception('No TAVILY_API_KEY found in environment variables')
|
||||
elif engine == "olostep":
|
||||
if config.OLOSTEP_API_KEY:
|
||||
return await asyncio.to_thread(
|
||||
search_olostep,
|
||||
config.OLOSTEP_API_KEY,
|
||||
query,
|
||||
config.WEB_SEARCH_RESULT_COUNT,
|
||||
config.WEB_SEARCH_DOMAIN_FILTER_LIST,
|
||||
)
|
||||
else:
|
||||
raise Exception("No OLOSTEP_API_KEY found in environment variables")
|
||||
elif engine == 'exa':
|
||||
if config.EXA_API_KEY:
|
||||
return await asyncio.to_thread(
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@
|
|||
'yandex',
|
||||
'youcom',
|
||||
'linkup',
|
||||
'openserp'
|
||||
'openserp',
|
||||
'olostep'
|
||||
];
|
||||
let webLoaderEngines = ['playwright', 'firecrawl', 'tavily', 'microsoft_web_iq', 'external'];
|
||||
|
||||
|
|
@ -572,6 +573,20 @@
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
{:else if webConfig.WEB_SEARCH_ENGINE === 'olostep'}
|
||||
<div class="mb-2.5 flex w-full flex-col">
|
||||
<div>
|
||||
<div class=" self-center text-xs text-gray-600 dark:text-gray-400 mb-1">
|
||||
{$i18n.t('Olostep API Key')}
|
||||
</div>
|
||||
|
||||
<SensitiveInput
|
||||
variant="settings"
|
||||
placeholder={$i18n.t('Enter Olostep API Key')}
|
||||
bind:value={webConfig.OLOSTEP_API_KEY}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{:else if webConfig.WEB_SEARCH_ENGINE === 'searchapi'}
|
||||
<div class="mb-2.5 flex w-full flex-col">
|
||||
<div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue