mirror of
https://github.com/open-webui/open-webui
synced 2025-02-23 05:38:41 +00:00
Update jina_search.py
Updated Jina's search function in order to use POST and make use of the result count passed by the user Note: Jina supports a max of 10 result count
This commit is contained in:
parent
14398ab628
commit
88db4ca7ba
@ -20,14 +20,26 @@ def search_jina(api_key: str, query: str, count: int) -> list[SearchResult]:
|
|||||||
list[SearchResult]: A list of search results
|
list[SearchResult]: A list of search results
|
||||||
"""
|
"""
|
||||||
jina_search_endpoint = "https://s.jina.ai/"
|
jina_search_endpoint = "https://s.jina.ai/"
|
||||||
headers = {"Accept": "application/json", "Authorization": f"Bearer {api_key}"}
|
|
||||||
url = str(URL(jina_search_endpoint + query))
|
headers = {
|
||||||
response = requests.get(url, headers=headers)
|
"Accept": "application/json",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": api_key,
|
||||||
|
"X-Retain-Images": "none"
|
||||||
|
}
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"q": query,
|
||||||
|
"count": count if count <= 10 else 10
|
||||||
|
}
|
||||||
|
|
||||||
|
url = str(URL(jina_search_endpoint))
|
||||||
|
response = requests.post(url, headers=headers, json=payload)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for result in data["data"][:count]:
|
for result in data["data"]:
|
||||||
results.append(
|
results.append(
|
||||||
SearchResult(
|
SearchResult(
|
||||||
link=result["url"],
|
link=result["url"],
|
||||||
|
Loading…
Reference in New Issue
Block a user