diff --git a/docs/own-instance.rst b/docs/own-instance.rst index 62099ce23..7d79f26c2 100644 --- a/docs/own-instance.rst +++ b/docs/own-instance.rst @@ -2,9 +2,9 @@ Why use a private instance? =========================== -.. sidebar:: Is it worth to run my own instance? +.. sidebar:: Is running my own instance worth it? - \.\. is a common question among SearXNG users. Before answering this + \.\.\.is a common question among SearXNG users. Before answering this question, see what options a SearXNG user has. .. contents:: @@ -12,13 +12,13 @@ Why use a private instance? :local: :backlinks: entry -Public instances are open to everyone who has access to its URL. Usually, these +Public instances are open to everyone who has access to their URL. Usually, they are operated by unknown parties (from the users' point of view). Private -instances can be used by a select group of people. It is for example a SearXNG of -group of friends or a company which can be accessed through VPN. Also it can be -single user one which runs on the user's laptop. +instances can be used by a select group of people, such as a SearXNG instance for a +group of friends, or a company which can be accessed through a VPN. Instances can also be +single-user instances, which run locally on the user's machine. -To gain more insight on how these instances work let's dive into how SearXNG +To gain more insight on how these instances work, let's dive into how SearXNG protects its users. .. _SearXNG protect privacy: @@ -26,26 +26,26 @@ protects its users. How does SearXNG protect privacy? ================================= -SearXNG protects the privacy of its users in multiple ways regardless of the type -of the instance (private, public). Removal of private data from search requests +SearXNG protects the privacy of its users in multiple ways, regardless of the type +of the instance (private or public). Removal of private data from search requests comes in three forms: - 1. removal of private data from requests going to search services - 2. not forwarding anything from a third party services through search services + 1. Removing private data from requests going to search services + 2. Not forwarding anything from third party services through search services (e.g. advertisement) - 3. removal of private data from requests going to the result pages + 3. Removing private data from requests going to the results pages Removing private data means not sending cookies to external search engines and generating a random browser profile for every request. Thus, it does not matter if a public or private instance handles the request, because it is anonymized in -both cases. IP addresses will be the IP of the instance. But SearXNG can be +both cases. The IP address used will be the IP of the instance, but SearXNG can also be configured to use proxy or Tor. `Result proxy `__ is supported, too. -SearXNG does not serve ads or tracking content unlike most search services. So +SearXNG does not serve ads or tracking content, unlike most search services. Therefore, private data is not forwarded to third parties who might monetize it. Besides -protecting users from search services, both referring page and search query are -hidden from visited result pages. +protecting users from search services, both the referring page and search query are +hidden from the results pages being visited. What are the consequences of using public instances? @@ -53,11 +53,11 @@ What are the consequences of using public instances? If someone uses a public instance, they have to trust the administrator of that instance. This means that the user of the public instance does not know whether -their requests are logged, aggregated and sent or sold to a third party. +their requests are logged, aggregated, and sent or sold to a third party. -Also, public instances without proper protection are more vulnerable to abusing -the search service, In this case the external service in exchange returns -CAPTCHAs or bans the IP of the instance. Thus, search requests return less +Also, public instances without proper protection are more vulnerable to abuse of +the search service, which may cause the external service to enforce +CAPTCHAs or to ban the IP address of the instance. Thus, search requests would return less results. I see. What about private instances? @@ -67,10 +67,10 @@ If users run their :ref:`own instances `, everything is in their control: the source code, logging settings and private data. Unknown instance administrators do not have to be trusted. -Furthermore, as the default settings of their instance is editable, there is no -need to use cookies to tailor SearXNG to their needs. So preferences will not be +Furthermore, as the default settings of their instance are editable, there is no +need to use cookies to tailor SearXNG to their needs and preferences will not reset to defaults when clearing browser cookies. As settings are stored on -their computer, it will not be accessible to others as long as their computer is +the user's computer, they will not be accessible to others as long as their computer is not compromised. Conclusion @@ -80,7 +80,7 @@ Always use an instance which is operated by people you trust. The privacy features of SearXNG are available to users no matter what kind of instance they use. -If someone is on the go or just wants to try SearXNG for the first time public -instances are the best choices. Additionally, public instance are making a -world a better place, because those who cannot or do not want to run an -instance, have access to a privacy respecting search service. +For those on the go, or just wanting to try SearXNG for the first time, public +instances are the best choice. Public instances are also making the +world a better place by giving those who cannot, or do not want to, run an +instance access to a privacy-respecting search service. diff --git a/requirements-dev.txt b/requirements-dev.txt index d5088b185..1c21d9ddf 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -22,4 +22,4 @@ wlc==1.15 coloredlogs==15.0.1 docutils<=0.21; python_version == '3.8' docutils>=0.21.2; python_version > '3.8' - +parameterized==0.9.0 diff --git a/searx/engines/cloudflareai.py b/searx/engines/cloudflareai.py new file mode 100644 index 000000000..fc1051efb --- /dev/null +++ b/searx/engines/cloudflareai.py @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Cloudflare AI engine""" + +from json import loads, dumps +from searx.exceptions import SearxEngineAPIException + +about = { + "website": 'https://ai.cloudflare.com', + "wikidata_id": None, + "official_api_documentation": 'https://developers.cloudflare.com/workers-ai', + "use_official_api": True, + "require_api_key": True, + "results": 'JSON', +} + +cf_account_id = '' +cf_ai_api = '' +cf_ai_gateway = '' + +cf_ai_model = '' +cf_ai_model_display_name = 'Cloudflare AI' + +# Assistant messages hint to the AI about the desired output format. Not all models support this role. +cf_ai_model_assistant = 'Keep your answers as short and effective as possible.' +# System messages define the AI's personality. You can use them to set rules and how you expect the AI to behave. +cf_ai_model_system = 'You are a self-aware language model who is honest and direct about any question from the user.' + + +def request(query, params): + + params['query'] = query + + params['url'] = f'https://gateway.ai.cloudflare.com/v1/{cf_account_id}/{cf_ai_gateway}/workers-ai/{cf_ai_model}' + + params['method'] = 'POST' + + params['headers']['Authorization'] = f'Bearer {cf_ai_api}' + params['headers']['Content-Type'] = 'application/json' + + params['data'] = dumps( + { + 'messages': [ + {'role': 'assistant', 'content': cf_ai_model_assistant}, + {'role': 'system', 'content': cf_ai_model_system}, + {'role': 'user', 'content': params['query']}, + ] + } + ).encode('utf-8') + + return params + + +def response(resp): + results = [] + json = loads(resp.text) + + if 'error' in json: + raise SearxEngineAPIException('Cloudflare AI error: ' + json['error']) + + if 'result' in json: + results.append( + { + 'content': json['result']['response'], + 'infobox': cf_ai_model_display_name, + } + ) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 3a09ca076..44245ab7c 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -482,6 +482,23 @@ engines: # to show premium or plus results too: # skip_premium: false + - name: cloudflareai + engine: cloudflareai + shortcut: cfai + # get api token and accont id from https://developers.cloudflare.com/workers-ai/get-started/rest-api/ + cf_account_id: 'your_cf_accout_id' + cf_ai_api: 'your_cf_api' + # create your ai gateway by https://developers.cloudflare.com/ai-gateway/get-started/creating-gateway/ + cf_ai_gateway: 'your_cf_ai_gateway_name' + # find the model name from https://developers.cloudflare.com/workers-ai/models/#text-generation + cf_ai_model: 'ai_model_name' + # custom your preferences + # cf_ai_model_display_name: 'Cloudflare AI' + # cf_ai_model_assistant: 'prompts_for_assistant_role' + # cf_ai_model_system: 'prompts_for_system_role' + timeout: 30 + disabled: true + # - name: core.ac.uk # engine: core # categories: science diff --git a/searx/templates/simple/preferences.html b/searx/templates/simple/preferences.html index 9baad1056..3e2111bba 100644 --- a/searx/templates/simple/preferences.html +++ b/searx/templates/simple/preferences.html @@ -8,7 +8,7 @@ {%- macro tab_header(name, id, label, checked) -%} -
+
{%- endmacro -%} {%- macro tab_footer() -%} @@ -27,11 +27,11 @@ {%- endif -%} {%- endmacro -%} -{%- macro checkbox_onoff_reversed(name, checked) -%} +{%- macro checkbox_onoff_reversed(name, checked, labelledby) -%} {%- endmacro -%} @@ -42,9 +42,9 @@
{{- '' -}} {{ _(plugin.name) }}{{- '' -}}
- {{- checkbox_onoff_reversed('plugin_' + plugin.id, plugin.id not in allowed_plugins) -}} + {{- checkbox_onoff_reversed('plugin_' + plugin.id, plugin.id not in allowed_plugins, 'plugin_labelledby' + plugin.id) -}}
{{- '' -}} -
+
{{- _(plugin.description) -}}
{{- '' -}}
@@ -90,7 +90,7 @@ {{- '' -}} {%- if stats[engine_name].time != None -%} {{- stats[engine_name].time -}}{{- '' -}} -