Coverage for open_webui/retrieval/web/mojeek.py: 32%

17 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 05:07 +0000

1from __future__ import annotations 

2 

3import logging 

4 

5import requests 

6from open_webui.retrieval.web.main import SearchResult, get_filtered_results 

7 

8log = logging.getLogger(__name__) 

9 

10 

11def search_mojeek(api_key: str, query: str, count: int, filter_list: list[str] | None = None) -> list[SearchResult]: 

12 """Search using Mojeek's Search API and return the results as a list of SearchResult objects. 

13 

14 Args: 

15 api_key (str): A Mojeek Search API key 

16 query (str): The query to search for 

17 """ 

18 url = 'https://api.mojeek.com/search' 

19 headers = { 

20 'Accept': 'application/json', 

21 } 

22 params = {'q': query, 'api_key': api_key, 'fmt': 'json', 't': count} 

23 

24 response = requests.get(url, headers=headers, params=params) 

25 response.raise_for_status() 

26 json_response = response.json() 

27 results = json_response.get('response', {}).get('results', []) 

28 print(results) 

29 if filter_list: 

30 results = get_filtered_results(results, filter_list) 

31 

32 return [ 

33 SearchResult(link=result['url'], title=result.get('title'), snippet=result.get('desc')) for result in results 

34 ]