From 88db4ca7babc232f9bbb2962bb078178deb038b6 Mon Sep 17 00:00:00 2001 From: binxn <78713335+binxn@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:30:27 +0100 Subject: [PATCH] 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 --- .../open_webui/retrieval/web/jina_search.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/retrieval/web/jina_search.py b/backend/open_webui/retrieval/web/jina_search.py index 3de6c1807..02af42ea6 100644 --- a/backend/open_webui/retrieval/web/jina_search.py +++ b/backend/open_webui/retrieval/web/jina_search.py @@ -20,14 +20,26 @@ def search_jina(api_key: str, query: str, count: int) -> list[SearchResult]: list[SearchResult]: A list of search results """ jina_search_endpoint = "https://s.jina.ai/" - headers = {"Accept": "application/json", "Authorization": f"Bearer {api_key}"} - url = str(URL(jina_search_endpoint + query)) - response = requests.get(url, headers=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() data = response.json() results = [] - for result in data["data"][:count]: + for result in data["data"]: results.append( SearchResult( link=result["url"],