Skip to content

Commit

Permalink
add searXNG instant answers
Browse files Browse the repository at this point in the history
  • Loading branch information
mamei16 committed Nov 2, 2024
1 parent bf64977 commit 637099b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ This is the default web search backend.

### SearXNG

Rudimentary support exists for SearXNG. To use a local or remote
SearXNG instance instead of DuckDuckGo, simply paste the URL into the
"SearXNG URL" text field of the "LLM Web Search" settings tab. The instance must support
To use a local or remote SearXNG instance instead of DuckDuckGo, simply paste the URL into the
"SearXNG URL" text field of the "LLM Web Search" settings tab (be sure to include `http://` or `https://`). The instance must support
returning results in JSON format.

#### Search parameters
Expand Down
8 changes: 7 additions & 1 deletion llm_web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def retrieve_from_duckduckgo(query: str, document_retriever: DocumentRetriever,


def retrieve_from_searxng(query: str, url: str, document_retriever: DocumentRetriever, max_results: int,
simple_search: bool = False):
instant_answers: bool, simple_search: bool = False):
yield f'Getting results from Searxng...'
headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
Expand All @@ -107,6 +107,12 @@ def retrieve_from_searxng(query: str, url: str, document_retriever: DocumentRetr
metadata={"source": result["url"]})
result_documents.append(result_document)
result_urls.append(result["url"])
answers = response_dict["answers"]
if instant_answers:
for answer in answers:
answer_document = Document(page_content=f"Title: {query}\n{answer}",
metadata={"source": "SearXNG instant answer"})
result_documents.append(answer_document)
pageno += 1
if simple_search:
retrieval_gen = Generator(document_retriever.retrieve_from_snippets(query, result_documents))
Expand Down
1 change: 1 addition & 0 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ def custom_generate_reply(question, original_question, seed, state, stopping_str
searxng_url,
document_retriever,
max_search_results,
instant_answers,
simple_search))
try:
for status_message in search_generator:
Expand Down

0 comments on commit 637099b

Please sign in to comment.