diff --git a/.gitignore b/.gitignore
index f50a65be0..f91e22b1e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,5 @@ gh-pages/
.idea/
searx/version_frozen.py
+
+gpt4all-falcon-q4_0.gguf
diff --git a/requirements.txt b/requirements.txt
index d9054e00e..61782d359 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -18,3 +18,4 @@ typing_extensions==4.8.0
fasttext-predict==0.9.2.2
pytomlpp==1.0.13
requests-html==0.10.0
+gpt4all==2.0.2
diff --git a/searx/templates/kvanDark/results.html b/searx/templates/kvanDark/results.html
index 043f6dcd5..a6604a33b 100644
--- a/searx/templates/kvanDark/results.html
+++ b/searx/templates/kvanDark/results.html
@@ -43,17 +43,6 @@
{{ _('Number of results') }}: {{ number_of_results }}
{%- endif -%}
- {%- if chat_box -%}
-
-
-
- {%- endif -%}
-
{%- if infoboxes -%}
{%- endif -%}
+ {%- if chat_box -%}
+
+
+
+ {%- endif -%}
+
{%- if suggestions -%}
{%- include 'kvanDark/elements/suggestions.html' -%}
{%- endif -%}
diff --git a/searx/webapp.py b/searx/webapp.py
index df8949b11..7707e3ce2 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -96,6 +96,7 @@ from searx.utils import (
from searx.version import VERSION_STRING, GIT_URL, GIT_BRANCH
from searx.query import RawTextQuery
from searx.plugins import Plugin, plugins, initialize as plugin_initialize
+import searx.plugins.chat
from searx.plugins.oa_doi_rewrite import get_doi_resolver
from searx.preferences import (
Preferences,
@@ -131,6 +132,9 @@ from searx.search import SearchWithPlugins, initialize as search_initialize
from searx.network import stream as http_stream, set_context_network_name
from searx.search.checker import get_result as checker_get_result
+from gpt4all import GPT4All
+from pathlib import Path
+
logger = logger.getChild('webapp')
# check secret_key
@@ -166,6 +170,8 @@ app.jinja_env.add_extension('jinja2.ext.loopcontrols') # pylint: disable=no-mem
app.jinja_env.filters['group_engines_in_tab'] = group_engines_in_tab # pylint: disable=no-member
app.secret_key = settings['server']['secret_key']
+# FIXME: This is a huge security vulnerability.
+extremely_bad_global_variable_search_query = None
class ExtendedRequest(flask.Request):
"""This class is never initialized and only used for type checking."""
@@ -623,6 +629,7 @@ def client_token(token=None):
@app.route('/search', methods=['GET', 'POST'])
def search():
+ global extremely_bad_global_variable_search_query
"""Search query in q and return results.
Supported outputs: html, json, csv, rss.
@@ -657,6 +664,8 @@ def search():
search_query, raw_text_query, _, _, selected_locale = get_search_query_from_webapp(
request.preferences, request.form
)
+ if searx.plugins.chat in request.user_plugins:
+ extremely_bad_global_variable_search_query = raw_text_query.getQuery()
search = SearchWithPlugins(search_query, request.user_plugins, request) # pylint: disable=redefined-outer-name
result_container = search.search()
@@ -1302,8 +1311,40 @@ def config():
@app.route('/get-chat-content')
def get_chat_content():
+ global extremely_bad_global_variable_search_query
# Retrieve chat content from wherever it's stored
- chat_content = {'chat_box': 'hello world', 'content': 'Response From Flask'}
+ # temp
+ chat_content = None
+ # retrieve from searx.plugins.chat
+ if extremely_bad_global_variable_search_query:
+ # do task
+ chat_content = {'chat_box': 'hello world', 'content': 'Not Generated Response Yet'}
+ model = GPT4All(model_name='gpt4all-falcon-q4_0.gguf',
+ model_path=(Path.cwd() / 'searx' / 'plugins'),
+ allow_download=False)
+
+ system_template = """
+### System Instructions:
+1. Provide concise, accurate, and directly relevant answers to queries.
+2. Emulate the style of a Google Answer Box, which includes straightforward and authoritative responses.
+3. Where appropriate, use bullet points or structured formatting to clearly present information.
+4. Avoid unnecessary elaborations and focus on the key points of the query.
+5. Ensure the information is up-to-date and factually correct.
+"""
+
+ prompt_template = """
+### Query:
+{0}
+
+### Expected Response:
+"""
+ with model.chat_session(system_template, prompt_template):
+ response = model.generate(extremely_bad_global_variable_search_query)
+ chat_content['content'] = str(response)
+
+ extremely_bad_global_variable_search_query = None
+
+
return jsonify(chat_content)