mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-24 17:06:53 +01:00
Update script.py
This commit is contained in:
parent
4373f5466d
commit
1a91a3cdad
@ -13,7 +13,7 @@ import torch
|
||||
|
||||
torch._C._jit_set_profiling_mode(False)
|
||||
|
||||
searx_integration_params = { # These can all be set in the settings.yml file
|
||||
params = { # These can all be set in the settings.yml file
|
||||
'enable_search': True,
|
||||
'include_first_result_content': True,
|
||||
'include_result_summary': False,
|
||||
@ -45,9 +45,9 @@ def url_to_text(url):
|
||||
for tag in soup.find_all(html_element_blacklist):
|
||||
tag.decompose()
|
||||
text = soup.get_text(strip=True)
|
||||
for string in searx_integration_params['removal_list']:
|
||||
for string in params['removal_list']:
|
||||
text.replace(string, " ")
|
||||
return text[0:searx_integration_params['max_characters_per_page']]
|
||||
return text[0:params['max_characters_per_page']]
|
||||
|
||||
def get_search_term(string): # This checks if you say "search ... about" something, and if the "Activate Searx integration" checkbox is ticked will search about that
|
||||
|
||||
@ -64,8 +64,8 @@ def get_search_term(string): # This checks if you say "search ... about" somethi
|
||||
def search_string(search_term): # This is the main logic that sends the API request to Searx and returns the text to add to the context
|
||||
|
||||
print("Searching about" + search_term + "...")
|
||||
query = f"{search_term} {searx_integration_params['extra_query_information']}"
|
||||
r = requests.get(searx_integration_params['searx_instance'], params={'q': query,'format': 'json','pageno': '1'})
|
||||
query = f"{search_term} {params['extra_query_information']}"
|
||||
r = requests.get(params['searx_instance'], params={'q': query,'format': 'json','pageno': '1'})
|
||||
try:
|
||||
searchdata = r.json()
|
||||
searchdata = searchdata['results']
|
||||
@ -73,22 +73,22 @@ def search_string(search_term): # This is the main logic that sends the API requ
|
||||
new_context = "Tell me that you could not find the results I asked for."
|
||||
else:
|
||||
new_context = f"This is new information from after your knowledge cutoff date about {search_term} :\n"
|
||||
if searx_integration_params['include_first_result_content']:
|
||||
for i in range(searx_integration_params['number_of_results']):
|
||||
if params['include_first_result_content']:
|
||||
for i in range(params['number_of_results']):
|
||||
new_context += url_to_text(searchdata[i]['url']) + "\n"
|
||||
if searx_integration_params['include_result_summary']:
|
||||
if params['include_result_summary']:
|
||||
for result in searchdata:
|
||||
if 'content' in result:
|
||||
new_context += result['content'] + "\n"
|
||||
new_context = new_context[0:searx_integration_params['max_total_characters']]
|
||||
new_context = new_context[0:params['max_total_characters']]
|
||||
finally:
|
||||
if searx_integration_params['console_log']:
|
||||
if params['console_log']:
|
||||
print(new_context)
|
||||
return new_context
|
||||
|
||||
def input_modifier(string):
|
||||
|
||||
if searx_integration_params['enable_search'] and searx_integration_params['searx_instance']:
|
||||
if params['enable_search'] and params['searx_instance']:
|
||||
if get_search_term(string):
|
||||
search_result = search_string(string)
|
||||
if search_result == "Tell me that you could not find the results I asked for.": # If it failed to get a result, ask the LLM to tell user it did
|
||||
@ -102,23 +102,23 @@ def ui():
|
||||
with gr.Accordion("Searx Integration", open=True):
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
enable_search = gr.Checkbox(value=searx_integration_params['enable_search'], label='Activate Searx integration')
|
||||
console_log = gr.Checkbox(value=searx_integration_params['console_log'], label='Display search results on console')
|
||||
include_first_result_content = gr.Checkbox(value=searx_integration_params['include_first_result_content'], label='Include content from the first result')
|
||||
number_of_results = gr.Slider(1,10,value=searx_integration_params['number_of_results'],step=1,label='Number of results to fetch')
|
||||
enable_search = gr.Checkbox(value=params['enable_search'], label='Activate Searx integration')
|
||||
console_log = gr.Checkbox(value=params['console_log'], label='Display search results on console')
|
||||
include_first_result_content = gr.Checkbox(value=params['include_first_result_content'], label='Include content from the first result')
|
||||
number_of_results = gr.Slider(1,10,value=params['number_of_results'],step=1,label='Number of results to fetch')
|
||||
with gr.Column():
|
||||
searx_instance = gr.Textbox(placeholder=searx_integration_params['searx_instance'], value=searx_integration_params['searx_instance'], label='Searx instance address')
|
||||
extra_query_information = gr.Textbox(placeholder=searx_integration_params['extra_query_information'], value=searx_integration_params['extra_query_information'], label='Extra info to pass in Searx query')
|
||||
include_result_summary = gr.Checkbox(value=searx_integration_params['include_result_summary'], label='Include summary from each search result')
|
||||
max_characters_per_page = gr.Slider(256,16384,value=searx_integration_params['max_characters_per_page'],step=64,label='Maximum characters per fetched pages')
|
||||
max_total_characters = gr.Slider(256,16384,value=searx_integration_params['max_total_characters'],step=64,label='Total max characters')
|
||||
searx_instance = gr.Textbox(placeholder=params['searx_instance'], value=params['searx_instance'], label='Searx instance address')
|
||||
extra_query_information = gr.Textbox(placeholder=params['extra_query_information'], value=params['extra_query_information'], label='Extra info to pass in Searx query')
|
||||
include_result_summary = gr.Checkbox(value=params['include_result_summary'], label='Include summary from each search result')
|
||||
max_characters_per_page = gr.Slider(256,16384,value=params['max_characters_per_page'],step=64,label='Maximum characters per fetched pages')
|
||||
max_total_characters = gr.Slider(256,16384,value=params['max_total_characters'],step=64,label='Total max characters')
|
||||
|
||||
enable_search.change(lambda x: searx_integration_params.update({"enable_search": x}), enable_search, None)
|
||||
console_log.change(lambda x: searx_integration_params.update({"console_display": x}), console_log, None)
|
||||
include_first_result_content.change(lambda x: searx_integration_params.update({"include_first_result_content": x}), include_first_result_content, None)
|
||||
include_result_summary.change(lambda x: searx_integration_params.update({"include_result_summary": x}), include_result_summary, None)
|
||||
number_of_results.change(lambda x: searx_integration_params.update({"number_of_results": x}), number_of_results, None)
|
||||
max_characters_per_page.change(lambda x: searx_integration_params.update({"max_characters_per_page": x}), max_characters_per_page, None)
|
||||
searx_instance.change(lambda x: searx_integration_params.update({"searx_instance": x}), searx_instance, None)
|
||||
extra_query_information.change(lambda x: searx_integration_params.update({"extra_query_information": x}), extra_query_information, None)
|
||||
max_total_characters.change(lambda x: searx_integration_params.update({"max_total_characters": x}), max_total_characters, None)
|
||||
enable_search.change(lambda x: params.update({"enable_search": x}), enable_search, None)
|
||||
console_log.change(lambda x: params.update({"console_display": x}), console_log, None)
|
||||
include_first_result_content.change(lambda x: params.update({"include_first_result_content": x}), include_first_result_content, None)
|
||||
include_result_summary.change(lambda x: params.update({"include_result_summary": x}), include_result_summary, None)
|
||||
number_of_results.change(lambda x: params.update({"number_of_results": x}), number_of_results, None)
|
||||
max_characters_per_page.change(lambda x: params.update({"max_characters_per_page": x}), max_characters_per_page, None)
|
||||
searx_instance.change(lambda x: params.update({"searx_instance": x}), searx_instance, None)
|
||||
extra_query_information.change(lambda x: params.update({"extra_query_information": x}), extra_query_information, None)
|
||||
max_total_characters.change(lambda x: params.update({"max_total_characters": x}), max_total_characters, None)
|
Loading…
Reference in New Issue
Block a user