mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-15 18:55:07 +03:00
29b4af6b98
Knowledge searches wrote the names and sources of the files they found to the server log at info level, and the SerpApi, Serply, Firecrawl, Yandex, Kagi, Mojeek and external web search engines wrote their whole results there, snippets included. Anyone who can read the logs could see what users looked up and what the model was given. These lines now log at debug, the same as the search queries, so they only show with GLOBAL_LOG_LEVEL=DEBUG. Fixes #34129
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import logging
|
|
from typing import Optional
|
|
|
|
import requests
|
|
from open_webui.retrieval.web.main import SearchResult, get_filtered_results
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def search_kagi(api_key: str, query: str, count: int, filter_list: Optional[list[str]] = None) -> list[SearchResult]:
|
|
"""Search using Kagi's Search API and return the results as a list of SearchResult objects.
|
|
|
|
The Search API will inherit the settings in your account, including results personalization and snippet length.
|
|
|
|
Args:
|
|
api_key (str): A Kagi Search API key
|
|
query (str): The query to search for
|
|
count (int): The number of results to return
|
|
"""
|
|
url = 'https://kagi.com/api/v1/search'
|
|
headers = {
|
|
'Authorization': f'Bearer {api_key}',
|
|
}
|
|
params = {'query': query, 'limit': count}
|
|
|
|
response = requests.post(url, headers=headers, json=params)
|
|
response.raise_for_status()
|
|
json_response = response.json()
|
|
search_results = json_response.get('data', {}).get('search', [])
|
|
if filter_list:
|
|
search_results = get_filtered_results(search_results, filter_list)
|
|
|
|
results = [
|
|
SearchResult(link=result['url'], title=result['title'], snippet=result.get('snippet'))
|
|
for result in search_results
|
|
]
|
|
|
|
log.debug('Kagi search results: %s', results)
|
|
|
|
return results
|