mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
add chat functionality
This commit is contained in:
parent
f797519944
commit
11a2d26393
4 changed files with 54 additions and 12 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -23,3 +23,5 @@ gh-pages/
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
searx/version_frozen.py
|
searx/version_frozen.py
|
||||||
|
|
||||||
|
gpt4all-falcon-q4_0.gguf
|
||||||
|
|
|
@ -18,3 +18,4 @@ typing_extensions==4.8.0
|
||||||
fasttext-predict==0.9.2.2
|
fasttext-predict==0.9.2.2
|
||||||
pytomlpp==1.0.13
|
pytomlpp==1.0.13
|
||||||
requests-html==0.10.0
|
requests-html==0.10.0
|
||||||
|
gpt4all==2.0.2
|
||||||
|
|
|
@ -43,17 +43,6 @@
|
||||||
<p id="result_count"><small>{{ _('Number of results') }}: {{ number_of_results }}</small></p>
|
<p id="result_count"><small>{{ _('Number of results') }}: {{ number_of_results }}</small></p>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
{%- if chat_box -%}
|
|
||||||
<div id="chat_box">
|
|
||||||
<details open class="sidebar-collapsable">
|
|
||||||
<summary class="title">{{ _('Chat') }}</summary>
|
|
||||||
{%- for chat_box in chat_box -%}
|
|
||||||
{%- include 'kvanDark/elements/chat_box.html' -%}
|
|
||||||
{%- endfor -%}
|
|
||||||
</details>
|
|
||||||
</div>
|
|
||||||
{%- endif -%}
|
|
||||||
|
|
||||||
{%- if infoboxes -%}
|
{%- if infoboxes -%}
|
||||||
<div id="infoboxes">
|
<div id="infoboxes">
|
||||||
<details open class="sidebar-collapsable">
|
<details open class="sidebar-collapsable">
|
||||||
|
@ -65,6 +54,15 @@
|
||||||
</div>
|
</div>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
|
{%- if chat_box -%}
|
||||||
|
<div id="chat_box">
|
||||||
|
<details open class="sidebar-collapsable">
|
||||||
|
<summary class="title">{{ _('Chat') }}</summary>
|
||||||
|
{%- include 'kvanDark/elements/chat_box.html' -%}
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
{%- if suggestions -%}
|
{%- if suggestions -%}
|
||||||
{%- include 'kvanDark/elements/suggestions.html' -%}
|
{%- include 'kvanDark/elements/suggestions.html' -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
|
@ -96,6 +96,7 @@ from searx.utils import (
|
||||||
from searx.version import VERSION_STRING, GIT_URL, GIT_BRANCH
|
from searx.version import VERSION_STRING, GIT_URL, GIT_BRANCH
|
||||||
from searx.query import RawTextQuery
|
from searx.query import RawTextQuery
|
||||||
from searx.plugins import Plugin, plugins, initialize as plugin_initialize
|
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.plugins.oa_doi_rewrite import get_doi_resolver
|
||||||
from searx.preferences import (
|
from searx.preferences import (
|
||||||
Preferences,
|
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.network import stream as http_stream, set_context_network_name
|
||||||
from searx.search.checker import get_result as checker_get_result
|
from searx.search.checker import get_result as checker_get_result
|
||||||
|
|
||||||
|
from gpt4all import GPT4All
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
logger = logger.getChild('webapp')
|
logger = logger.getChild('webapp')
|
||||||
|
|
||||||
# check secret_key
|
# 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.jinja_env.filters['group_engines_in_tab'] = group_engines_in_tab # pylint: disable=no-member
|
||||||
app.secret_key = settings['server']['secret_key']
|
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):
|
class ExtendedRequest(flask.Request):
|
||||||
"""This class is never initialized and only used for type checking."""
|
"""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'])
|
@app.route('/search', methods=['GET', 'POST'])
|
||||||
def search():
|
def search():
|
||||||
|
global extremely_bad_global_variable_search_query
|
||||||
"""Search query in q and return results.
|
"""Search query in q and return results.
|
||||||
|
|
||||||
Supported outputs: html, json, csv, rss.
|
Supported outputs: html, json, csv, rss.
|
||||||
|
@ -657,6 +664,8 @@ def search():
|
||||||
search_query, raw_text_query, _, _, selected_locale = get_search_query_from_webapp(
|
search_query, raw_text_query, _, _, selected_locale = get_search_query_from_webapp(
|
||||||
request.preferences, request.form
|
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
|
search = SearchWithPlugins(search_query, request.user_plugins, request) # pylint: disable=redefined-outer-name
|
||||||
result_container = search.search()
|
result_container = search.search()
|
||||||
|
|
||||||
|
@ -1302,8 +1311,40 @@ def config():
|
||||||
|
|
||||||
@app.route('/get-chat-content')
|
@app.route('/get-chat-content')
|
||||||
def get_chat_content():
|
def get_chat_content():
|
||||||
|
global extremely_bad_global_variable_search_query
|
||||||
# Retrieve chat content from wherever it's stored
|
# 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)
|
return jsonify(chat_content)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue