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
6b8290fa
Unverified
Commit
6b8290fa
authored
Jun 17, 2024
by
Que Nguyen
Committed by
GitHub
Jun 17, 2024
Browse files
Set filter_list as optional param in serper.py
parent
9c446d9f
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/serper.py
backend/apps/rag/search/serper.py
+6
-5
No files found.
backend/apps/rag/search/serper.py
View file @
6b8290fa
import
json
import
json
import
logging
import
logging
from
typing
import
List
from
typing
import
List
,
Optional
import
requests
import
requests
from
apps.rag.search.main
import
SearchResult
,
filter
_by_whitelist
from
apps.rag.search.main
import
SearchResult
,
get_
filter
ed_results
from
config
import
SRC_LOG_LEVELS
from
config
import
SRC_LOG_LEVELS
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
log
.
setLevel
(
SRC_LOG_LEVELS
[
"RAG"
])
log
.
setLevel
(
SRC_LOG_LEVELS
[
"RAG"
])
def
search_serper
(
api_key
:
str
,
query
:
str
,
count
:
int
,
whitelist
:
List
[
str
])
->
list
[
SearchResult
]:
def
search_serper
(
api_key
:
str
,
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
List
[
str
]
]
=
None
)
->
list
[
SearchResult
]:
"""Search using serper.dev's API and return the results as a list of SearchResult objects.
"""Search using serper.dev's API and return the results as a list of SearchResult objects.
Args:
Args:
...
@@ -29,12 +29,13 @@ def search_serper(api_key: str, query: str, count: int, whitelist:List[str]) ->
...
@@ -29,12 +29,13 @@ def search_serper(api_key: str, query: str, count: int, whitelist:List[str]) ->
results
=
sorted
(
results
=
sorted
(
json_response
.
get
(
"organic"
,
[]),
key
=
lambda
x
:
x
.
get
(
"position"
,
0
)
json_response
.
get
(
"organic"
,
[]),
key
=
lambda
x
:
x
.
get
(
"position"
,
0
)
)
)
filtered_results
=
filter_by_whitelist
(
results
,
whitelist
)
if
filter_list
:
results
=
get_filtered_results
(
results
,
filter_list
)
return
[
return
[
SearchResult
(
SearchResult
(
link
=
result
[
"link"
],
link
=
result
[
"link"
],
title
=
result
.
get
(
"title"
),
title
=
result
.
get
(
"title"
),
snippet
=
result
.
get
(
"description"
),
snippet
=
result
.
get
(
"description"
),
)
)
for
result
in
filtered_
results
[:
count
]
for
result
in
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