openwebui 对接 searxng 时 无法查询到联网信息,利用bing搜索,每次返回json是正常的
秘密代码:
- 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¢er_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 源码 调整前
- import logging
- from typing import Optional
- import requests
- from open_webui.retrieval.web.main import SearchResult, get_filtered_results
- from open_webui.env import SRC_LOG_LEVELS
- log = logging.getLogger(__name__)
- log.setLevel(SRC_LOG_LEVELS["RAG"])
- def search_searxng(
- query_url: str,
- query: str,
- count: int,
- filter_list: Optional[list[str]] = None,
- **kwargs,
- ) -> list[SearchResult]:
- """
- Search a SearXNG instance for a given query and return the results as a list of SearchResult objects.
- The function allows passing additional parameters such as language or time_range to tailor the search result.
- Args:
- query_url (str): The base URL of the SearXNG server.
- query (str): The search term or question to find in the SearXNG database.
- count (int): The maximum number of results to retrieve from the search.
- Keyword Args:
- language (str): Language filter for the search results; e.g., "en-US". Defaults to an empty string.
- safesearch (int): Safe search filter for safer web results; 0 = off, 1 = moderate, 2 = strict. Defaults to 1 (moderate).
- time_range (str): Time range for filtering results by date; e.g., "2023-04-05..today" or "all-time". Defaults to ''.
- categories: (Optional[list[str]]): Specific categories within which the search should be performed, defaulting to an empty string if not provided.
- Returns:
- list[SearchResult]: A list of SearchResults sorted by relevance score in descending order.
- Raise:
- requests.exceptions.RequestException: If a request error occurs during the search process.
- """
- # Default values for optional parameters are provided as empty strings or None when not specified.
- language = kwargs.get("language", "en-US")
- safesearch = kwargs.get("safesearch", "1")
- time_range = kwargs.get("time_range", "")
- categories = "".join(kwargs.get("categories", []))
- params = {
- "q": query,
- "format": "json",
- "pageno": 1,
- "safesearch": safesearch,
- "language": language,
- "time_range": time_range,
- "categories": categories,
- "theme": "simple",
- "image_proxy": 0,
- }
- # Legacy query format
- if "<query>" in query_url:
- # Strip all query parameters from the URL
- query_url = query_url.split("?")[0]
- log.debug(f"searching {query_url}")
- response = requests.get(
- query_url,
- headers={
- "User-Agent": "Open WebUI (https://github.com/open-webui/open-webui) RAG Bot",
- "Accept": "text/html",
- "Accept-Encoding": "gzip, deflate",
- "Accept-Language": "en-US,en;q=0.5",
- "Connection": "keep-alive",
- },
- params=params,
- )
- response.raise_for_status() # Raise an exception for HTTP errors.
- json_response = response.json()
- results = json_response.get("results", [])
- sorted_results = sorted(results, key=lambda x: x.get("score", 0), reverse=True)
- if filter_list:
- sorted_results = get_filtered_results(sorted_results, filter_list)
- return [
- SearchResult(
- link=result["url"], title=result.get("title"), snippet=result.get("content")
- )
- for result in sorted_results[:count]
- ]
复制代码 调整后
- import logging
- from typing import Optional
- import requests
- from open_webui.retrieval.web.main import SearchResult, get_filtered_results
- from open_webui.env import SRC_LOG_LEVELS
- log = logging.getLogger(__name__)
- log.setLevel(SRC_LOG_LEVELS["RAG"])
- def search_searxng(
- query_url: str,
- query: str,
- count: int,
- filter_list: Optional[list[str]] = None,
- **kwargs,
- ) -> list[SearchResult]:
- """
- Search a SearXNG instance for a given query and return the results as a list of SearchResult objects.
- The function allows passing additional parameters such as language or time_range to tailor the search result.
- Args:
- query_url (str): The base URL of the SearXNG server.
- query (str): The search term or question to find in the SearXNG database.
- count (int): The maximum number of results to retrieve from the search.
- Keyword Args:
- language (str): Language filter for the search results; e.g., "en-US". Defaults to an empty string.
- safesearch (int): Safe search filter for safer web results; 0 = off, 1 = moderate, 2 = strict. Defaults to 1 (moderate).
- time_range (str): Time range for filtering results by date; e.g., "2023-04-05..today" or "all-time". Defaults to ''.
- categories: (Optional[list[str]]): Specific categories within which the search should be performed, defaulting to an empty string if not provided.
- Returns:
- list[SearchResult]: A list of SearchResults sorted by relevance score in descending order.
- Raise:
- requests.exceptions.RequestException: If a request error occurs during the search process.
- """
- # Default values for optional parameters are provided as empty strings or None when not specified.
- language = kwargs.get("language", "zh")
- safesearch = kwargs.get("safesearch", "1")
- time_range = kwargs.get("time_range", "")
- categories = "".join(kwargs.get("categories", []))
- params = {
- "q": query,
- "format": "json",
- "pageno": 1,
- "safesearch": safesearch,
- "language": language,
- "time_range": time_range,
- "categories": categories,
- "theme": "simple",
- "image_proxy": 0,
- "locale":"zh-Hans-CN",
-
- "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"
- }
- # Legacy query format
- if "<query>" in query_url:
- # Strip all query parameters from the URL
- query_url = query_url.split("?")[0]
- log.debug(f"searching {query_url}")
- response = requests.get(
- query_url,
- headers={
- "User-Agent": "Open WebUI (https://github.com/open-webui/open-webui) RAG Bot",
- "Accept": "text/html",
- "Accept-Encoding": "gzip, deflate",
- "Accept-Language": "en-US,en;q=0.5",
- "Connection": "keep-alive",
- },
- params=params,
- )
- response.raise_for_status() # Raise an exception for HTTP errors.
- json_response = response.json()
- results = json_response.get("results", [])
- sorted_results = sorted(results, key=lambda x: x.get("score", 0), reverse=True)
- if filter_list:
- sorted_results = get_filtered_results(sorted_results, filter_list)
- return [
- SearchResult(
- link=result["url"], title=result.get("title"), snippet=result.get("content")
- )
- for result in sorted_results[:count]
- ]
复制代码 改完 看到哀求参数

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

现实搜索到网页是正确的,结果就 是不可,是模型题目还是openwebui题目?
搞不来了,放弃
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |