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
7c9fb919
Commit
7c9fb919
authored
Jun 22, 2024
by
Yash-1511
Browse files
feat: add jina_search as new websearch provider
parent
9e4dd4b8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
1 deletion
+46
-1
backend/apps/rag/main.py
backend/apps/rag/main.py
+3
-0
backend/apps/rag/search/jina_search.py
backend/apps/rag/search/jina_search.py
+41
-0
src/lib/components/admin/Settings/WebSearch.svelte
src/lib/components/admin/Settings/WebSearch.svelte
+2
-1
No files found.
backend/apps/rag/main.py
View file @
7c9fb919
...
...
@@ -74,6 +74,7 @@ from apps.rag.search.serpstack import search_serpstack
from
apps.rag.search.serply
import
search_serply
from
apps.rag.search.duckduckgo
import
search_duckduckgo
from
apps.rag.search.tavily
import
search_tavily
from
apps.rag.search.jina_search
import
search_jina
from
utils.misc
import
(
calculate_sha256
,
...
...
@@ -841,6 +842,8 @@ def search_web(engine: str, query: str) -> list[SearchResult]:
)
else
:
raise
Exception
(
"No TAVILY_API_KEY found in environment variables"
)
elif
engine
==
"jina"
:
return
search_jina
(
query
,
app
.
state
.
config
.
RAG_WEB_SEARCH_RESULT_COUNT
)
else
:
raise
Exception
(
"No search engine API key found in environment variables"
)
...
...
backend/apps/rag/search/jina_search.py
0 → 100644
View file @
7c9fb919
import
logging
import
requests
from
yarl
import
URL
from
apps.rag.search.main
import
SearchResult
from
config
import
SRC_LOG_LEVELS
log
=
logging
.
getLogger
(
__name__
)
log
.
setLevel
(
SRC_LOG_LEVELS
[
"RAG"
])
def
search_jina
(
query
:
str
,
count
:
int
)
->
list
[
SearchResult
]:
"""
Search using Jina's Search API and return the results as a list of SearchResult objects.
Args:
query (str): The query to search for
count (int): The number of results to return
Returns:
List[SearchResult]: A list of search results
"""
jina_search_endpoint
=
"https://s.jina.ai/"
headers
=
{
"Accept"
:
"application/json"
,
}
url
=
str
(
URL
(
jina_search_endpoint
+
query
))
response
=
requests
.
get
(
url
,
headers
=
headers
)
response
.
raise_for_status
()
data
=
response
.
json
()
results
=
[]
for
result
in
data
[
"data"
][:
count
]:
results
.
append
(
SearchResult
(
link
=
result
[
"url"
],
title
=
result
.
get
(
"title"
),
snippet
=
result
.
get
(
"content"
),
)
)
return
results
\ No newline at end of file
src/lib/components/admin/Settings/WebSearch.svelte
View file @
7c9fb919
...
...
@@ -19,7 +19,8 @@
'serper',
'serply',
'duckduckgo',
'tavily'
'tavily',
'jina'
];
let youtubeLanguage = 'en';
...
...
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