open-webui/backend/apps/rag/search/main.py
Que Nguyen 3cc0e3ecb6
Refactor rag/main.py
Renamed function get_filtered_results
2024-06-17 14:36:26 +07:00

20 lines
546 B
Python

from typing import Optional
from urllib.parse import urlparse
from pydantic import BaseModel
def get_filtered_results(results, filter_list):
if not filter_list:
return results
filtered_results = []
for result in results:
domain = urlparse(result["url"]).netloc
if any(domain.endswith(filtered_domain) for filtered_domain in filter_list):
filtered_results.append(result)
return filtered_results
class SearchResult(BaseModel):
link: str
title: Optional[str]
snippet: Optional[str]