mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-23 22:11:28 -05:00
The external reranker, Exa and Ollama web search wrote the full user query to the server log at info level, and reusing generated search queries logged them as well. Those lines no longer include the query. A failing external reranker also logged the provider URL in its error message along with a stack trace; it now logs only the error type. Co-authored-by: manooll <16244686+manooll@users.noreply.github.com>
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
import logging
|
|
from dataclasses import dataclass
|
|
from typing import Optional
|
|
|
|
import requests
|
|
from open_webui.retrieval.web.main import SearchResult, get_filtered_results
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def search_ollama_cloud(
|
|
url: str,
|
|
api_key: str,
|
|
query: str,
|
|
count: int,
|
|
filter_list: Optional[list[str]] = None,
|
|
) -> list[SearchResult]:
|
|
"""Search using Ollama Search API and return the results as a list of SearchResult objects.
|
|
|
|
Args:
|
|
api_key (str): A Ollama Search API key
|
|
query (str): The query to search for
|
|
count (int): Number of results to return
|
|
filter_list (Optional[list[str]]): List of domains to filter results by
|
|
"""
|
|
log.info('Searching with Ollama')
|
|
|
|
headers = {'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json'}
|
|
payload = {'query': query, 'max_results': count}
|
|
|
|
try:
|
|
response = requests.post(f'{url}/api/web_search', headers=headers, json=payload)
|
|
response.raise_for_status()
|
|
data = response.json()
|
|
|
|
results = data.get('results', [])
|
|
log.info('Found %s results', len(results))
|
|
|
|
if filter_list:
|
|
results = get_filtered_results(results, filter_list)
|
|
|
|
return [
|
|
SearchResult(
|
|
link=result.get('url', ''),
|
|
title=result.get('title', ''),
|
|
snippet=result.get('content', ''),
|
|
)
|
|
for result in results
|
|
]
|
|
except Exception as e:
|
|
log.error(f'Error searching Ollama: {e}')
|
|
return []
|