Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
9c446d9f
Unverified
Commit
9c446d9f
authored
Jun 17, 2024
by
Que Nguyen
Committed by
GitHub
Jun 17, 2024
Browse files
Set filter_list as optional param in searxng.py
parent
3cc0e3ec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
backend/apps/rag/search/searxng.py
backend/apps/rag/search/searxng.py
+6
-5
No files found.
backend/apps/rag/search/searxng.py
View file @
9c446d9f
import
logging
import
requests
from
typing
import
List
from
typing
import
List
,
Optional
from
apps.rag.search.main
import
SearchResult
from
apps.rag.search.main
import
SearchResult
,
get_filtered_results
from
config
import
SRC_LOG_LEVELS
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -11,7 +11,7 @@ log.setLevel(SRC_LOG_LEVELS["RAG"])
def
search_searxng
(
query_url
:
str
,
query
:
str
,
count
:
int
,
whitelist
:
List
[
str
],
**
kwargs
query_url
:
str
,
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
List
[
str
]
]
=
None
,
**
kwargs
)
->
List
[
SearchResult
]:
"""
Search a SearXNG instance for a given query and return the results as a list of SearchResult objects.
...
...
@@ -78,10 +78,11 @@ def search_searxng(
json_response
=
response
.
json
()
results
=
json_response
.
get
(
"results"
,
[])
sorted_results
=
sorted
(
results
,
key
=
lambda
x
:
x
.
get
(
"score"
,
0
),
reverse
=
True
)
filtered_results
=
filter_by_whitelist
(
sorted_results
,
whitelist
)
if
filter_list
:
sorted_results
=
get_filtered_results
(
sorted_results
,
whitelist
)
return
[
SearchResult
(
link
=
result
[
"url"
],
title
=
result
.
get
(
"title"
),
snippet
=
result
.
get
(
"content"
)
)
for
result
in
filter
ed_results
[:
count
]
for
result
in
sort
ed_results
[:
count
]
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment