[原创]openwebui办理searxng通过接口哀求不乐成题目

打印 上一主题 下一主题

主题 953|帖子 953|积分 2859

openwebui 对接 searxng 时 无法查询到联网信息,利用bing搜索,每次返回json是正常的

秘密代码:
  1. http://172.30.254.200:8080/search?q=北京市天气&format=json&language=zh&time_range=&safesearch=0&language=zh&locale=zh-Hans-CN&autocomplete=&favicon_resolver=&image_proxy=0&method=POST&safesearch=0&theme=simple&results_on_new_tab=0&doi_resolver=oadoi.org&simple_style=auto&center_alignment=0&advanced_search=0&query_in_title=0&infinite_scroll=0&search_on_category_select=1&hotkeys=default&url_formatting=pretty&disabled_plugins=&enabled_plugins=&tokens=&categories=general&disabled_engines="wikipedia__general\054currency__general\054wikidata__general\054duckduckgo__general\054google__general\054lingva__general\054qwant__general\054startpage__general\054dictzone__general\054mymemory translated__general\054brave__general"&enabled_engines=bing__general
复制代码
官方教程是如许设置的  非常不稳固,经常搜索不到结果


 searxng.py 源码 调整前
  1. import logging
  2. from typing import Optional
  3. import requests
  4. from open_webui.retrieval.web.main import SearchResult, get_filtered_results
  5. from open_webui.env import SRC_LOG_LEVELS
  6. log = logging.getLogger(__name__)
  7. log.setLevel(SRC_LOG_LEVELS["RAG"])
  8. def search_searxng(
  9.     query_url: str,
  10.     query: str,
  11.     count: int,
  12.     filter_list: Optional[list[str]] = None,
  13.     **kwargs,
  14. ) -> list[SearchResult]:
  15.     """
  16.     Search a SearXNG instance for a given query and return the results as a list of SearchResult objects.
  17.     The function allows passing additional parameters such as language or time_range to tailor the search result.
  18.     Args:
  19.         query_url (str): The base URL of the SearXNG server.
  20.         query (str): The search term or question to find in the SearXNG database.
  21.         count (int): The maximum number of results to retrieve from the search.
  22.     Keyword Args:
  23.         language (str): Language filter for the search results; e.g., "en-US". Defaults to an empty string.
  24.         safesearch (int): Safe search filter for safer web results; 0 = off, 1 = moderate, 2 = strict. Defaults to 1 (moderate).
  25.         time_range (str): Time range for filtering results by date; e.g., "2023-04-05..today" or "all-time". Defaults to ''.
  26.         categories: (Optional[list[str]]): Specific categories within which the search should be performed, defaulting to an empty string if not provided.
  27.     Returns:
  28.         list[SearchResult]: A list of SearchResults sorted by relevance score in descending order.
  29.     Raise:
  30.         requests.exceptions.RequestException: If a request error occurs during the search process.
  31.     """
  32.     # Default values for optional parameters are provided as empty strings or None when not specified.
  33.     language = kwargs.get("language", "en-US")
  34.     safesearch = kwargs.get("safesearch", "1")
  35.     time_range = kwargs.get("time_range", "")
  36.     categories = "".join(kwargs.get("categories", []))
  37.     params = {
  38.         "q": query,
  39.         "format": "json",
  40.         "pageno": 1,
  41.         "safesearch": safesearch,
  42.         "language": language,
  43.         "time_range": time_range,
  44.         "categories": categories,
  45.         "theme": "simple",
  46.         "image_proxy": 0,
  47.     }
  48.     # Legacy query format
  49.     if "<query>" in query_url:
  50.         # Strip all query parameters from the URL
  51.         query_url = query_url.split("?")[0]
  52.     log.debug(f"searching {query_url}")
  53.     response = requests.get(
  54.         query_url,
  55.         headers={
  56.             "User-Agent": "Open WebUI (https://github.com/open-webui/open-webui) RAG Bot",
  57.             "Accept": "text/html",
  58.             "Accept-Encoding": "gzip, deflate",
  59.             "Accept-Language": "en-US,en;q=0.5",
  60.             "Connection": "keep-alive",
  61.         },
  62.         params=params,
  63.     )
  64.     response.raise_for_status()  # Raise an exception for HTTP errors.
  65.     json_response = response.json()
  66.     results = json_response.get("results", [])
  67.     sorted_results = sorted(results, key=lambda x: x.get("score", 0), reverse=True)
  68.     if filter_list:
  69.         sorted_results = get_filtered_results(sorted_results, filter_list)
  70.     return [
  71.         SearchResult(
  72.             link=result["url"], title=result.get("title"), snippet=result.get("content")
  73.         )
  74.         for result in sorted_results[:count]
  75.     ]
复制代码
 调整后
  1. import logging
  2. from typing import Optional
  3. import requests
  4. from open_webui.retrieval.web.main import SearchResult, get_filtered_results
  5. from open_webui.env import SRC_LOG_LEVELS
  6. log = logging.getLogger(__name__)
  7. log.setLevel(SRC_LOG_LEVELS["RAG"])
  8. def search_searxng(
  9.     query_url: str,
  10.     query: str,
  11.     count: int,
  12.     filter_list: Optional[list[str]] = None,
  13.     **kwargs,
  14. ) -> list[SearchResult]:
  15.     """
  16.     Search a SearXNG instance for a given query and return the results as a list of SearchResult objects.
  17.     The function allows passing additional parameters such as language or time_range to tailor the search result.
  18.     Args:
  19.         query_url (str): The base URL of the SearXNG server.
  20.         query (str): The search term or question to find in the SearXNG database.
  21.         count (int): The maximum number of results to retrieve from the search.
  22.     Keyword Args:
  23.         language (str): Language filter for the search results; e.g., "en-US". Defaults to an empty string.
  24.         safesearch (int): Safe search filter for safer web results; 0 = off, 1 = moderate, 2 = strict. Defaults to 1 (moderate).
  25.         time_range (str): Time range for filtering results by date; e.g., "2023-04-05..today" or "all-time". Defaults to ''.
  26.         categories: (Optional[list[str]]): Specific categories within which the search should be performed, defaulting to an empty string if not provided.
  27.     Returns:
  28.         list[SearchResult]: A list of SearchResults sorted by relevance score in descending order.
  29.     Raise:
  30.         requests.exceptions.RequestException: If a request error occurs during the search process.
  31.     """
  32.     # Default values for optional parameters are provided as empty strings or None when not specified.
  33.     language = kwargs.get("language", "zh")
  34.     safesearch = kwargs.get("safesearch", "1")
  35.     time_range = kwargs.get("time_range", "")
  36.     categories = "".join(kwargs.get("categories", []))
  37.     params = {
  38.         "q": query,
  39.         "format": "json",
  40.         "pageno": 1,
  41.         "safesearch": safesearch,
  42.         "language": language,
  43.         "time_range": time_range,
  44.         "categories": categories,
  45.         "theme": "simple",
  46.         "image_proxy": 0,
  47.         "locale":"zh-Hans-CN",        
  48. "disabled_engines":"wikipedia__general\054currency__general\054wikidata__general\054duckduckgo__general\054google__general\054lingva__general\054qwant__general\054startpage__general\054dictzone__general\054mymemory translated__general\054brave__general",
  49.         "enabled_engines":"bing__general"
  50.     }
  51.     # Legacy query format
  52.     if "<query>" in query_url:
  53.         # Strip all query parameters from the URL
  54.         query_url = query_url.split("?")[0]
  55.     log.debug(f"searching {query_url}")
  56.     response = requests.get(
  57.         query_url,
  58.         headers={
  59.             "User-Agent": "Open WebUI (https://github.com/open-webui/open-webui) RAG Bot",
  60.             "Accept": "text/html",
  61.             "Accept-Encoding": "gzip, deflate",
  62.             "Accept-Language": "en-US,en;q=0.5",
  63.             "Connection": "keep-alive",
  64.         },
  65.         params=params,
  66.     )
  67.     response.raise_for_status()  # Raise an exception for HTTP errors.
  68.     json_response = response.json()
  69.     results = json_response.get("results", [])
  70.     sorted_results = sorted(results, key=lambda x: x.get("score", 0), reverse=True)
  71.     if filter_list:
  72.         sorted_results = get_filtered_results(sorted_results, filter_list)
  73.     return [
  74.         SearchResult(
  75.             link=result["url"], title=result.get("title"), snippet=result.get("content")
  76.         )
  77.         for result in sorted_results[:count]
  78.     ]
复制代码
 改完 看到哀求参数

总结   openwebui 对接SearXNG 有bug 我修不来 ,提出的关键词就会被修改掉为什么呢?
接着搞,把搜索关键字写死

 出结果了
 
 现实搜索到网页是正确的,结果就 是不可,是模型题目还是openwebui题目?

搞不来了,放弃 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

何小豆儿在此

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表