mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
enh/fix: google pse referer header
This commit is contained in:
parent
03f207b803
commit
a4fd26b478
2 changed files with 6 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ def search_google_pse(
|
||||||
query: str,
|
query: str,
|
||||||
count: int,
|
count: int,
|
||||||
filter_list: Optional[list[str]] = None,
|
filter_list: Optional[list[str]] = None,
|
||||||
|
referer: Optional[str] = None,
|
||||||
) -> list[SearchResult]:
|
) -> list[SearchResult]:
|
||||||
"""Search using Google's Programmable Search Engine API and return the results as a list of SearchResult objects.
|
"""Search using Google's Programmable Search Engine API and return the results as a list of SearchResult objects.
|
||||||
Handles pagination for counts greater than 10.
|
Handles pagination for counts greater than 10.
|
||||||
|
|
@ -30,7 +31,11 @@ def search_google_pse(
|
||||||
list[SearchResult]: A list of SearchResult objects.
|
list[SearchResult]: A list of SearchResult objects.
|
||||||
"""
|
"""
|
||||||
url = "https://www.googleapis.com/customsearch/v1"
|
url = "https://www.googleapis.com/customsearch/v1"
|
||||||
|
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
|
if referer:
|
||||||
|
headers["Referer"] = referer
|
||||||
|
|
||||||
all_results = []
|
all_results = []
|
||||||
start_index = 1 # Google PSE start parameter is 1-based
|
start_index = 1 # Google PSE start parameter is 1-based
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1875,6 +1875,7 @@ def search_web(request: Request, engine: str, query: str) -> list[SearchResult]:
|
||||||
query,
|
query,
|
||||||
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,
|
||||||
|
referer=request.app.state.config.WEBUI_URL,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue