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
29f904db
Commit
29f904db
authored
Aug 14, 2024
by
Michael Poluektov
Browse files
remove List imports
parent
038fc48a
Changes
38
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
60 additions
and
60 deletions
+60
-60
backend/apps/audio/main.py
backend/apps/audio/main.py
+2
-2
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+5
-5
backend/apps/openai/main.py
backend/apps/openai/main.py
+3
-3
backend/apps/rag/main.py
backend/apps/rag/main.py
+4
-4
backend/apps/rag/search/brave.py
backend/apps/rag/search/brave.py
+2
-2
backend/apps/rag/search/duckduckgo.py
backend/apps/rag/search/duckduckgo.py
+3
-3
backend/apps/rag/search/google_pse.py
backend/apps/rag/search/google_pse.py
+2
-2
backend/apps/rag/search/jina_search.py
backend/apps/rag/search/jina_search.py
+1
-1
backend/apps/rag/search/searxng.py
backend/apps/rag/search/searxng.py
+5
-5
backend/apps/rag/search/serper.py
backend/apps/rag/search/serper.py
+2
-2
backend/apps/rag/search/serply.py
backend/apps/rag/search/serply.py
+2
-2
backend/apps/rag/search/serpstack.py
backend/apps/rag/search/serpstack.py
+2
-2
backend/apps/rag/search/tavily.py
backend/apps/rag/search/tavily.py
+1
-1
backend/apps/rag/utils.py
backend/apps/rag/utils.py
+4
-4
backend/apps/webui/models/chats.py
backend/apps/webui/models/chats.py
+9
-9
backend/apps/webui/models/documents.py
backend/apps/webui/models/documents.py
+2
-2
backend/apps/webui/models/files.py
backend/apps/webui/models/files.py
+2
-2
backend/apps/webui/models/functions.py
backend/apps/webui/models/functions.py
+5
-5
backend/apps/webui/models/memories.py
backend/apps/webui/models/memories.py
+3
-3
backend/apps/webui/models/models.py
backend/apps/webui/models/models.py
+1
-1
No files found.
backend/apps/audio/main.py
View file @
29f904db
...
...
@@ -438,7 +438,7 @@ def transcribe(
)
def
get_available_models
()
->
L
ist
[
dict
]:
def
get_available_models
()
->
l
ist
[
dict
]:
if
app
.
state
.
config
.
TTS_ENGINE
==
"openai"
:
return
[{
"id"
:
"tts-1"
},
{
"id"
:
"tts-1-hd"
}]
elif
app
.
state
.
config
.
TTS_ENGINE
==
"elevenlabs"
:
...
...
@@ -466,7 +466,7 @@ async def get_models(user=Depends(get_verified_user)):
return
{
"models"
:
get_available_models
()}
def
get_available_voices
()
->
L
ist
[
dict
]:
def
get_available_voices
()
->
l
ist
[
dict
]:
if
app
.
state
.
config
.
TTS_ENGINE
==
"openai"
:
return
[
{
"name"
:
"alloy"
,
"id"
:
"alloy"
},
...
...
backend/apps/ollama/main.py
View file @
29f904db
...
...
@@ -114,7 +114,7 @@ async def get_ollama_api_urls(user=Depends(get_admin_user)):
class
UrlUpdateForm
(
BaseModel
):
urls
:
L
ist
[
str
]
urls
:
l
ist
[
str
]
@
app
.
post
(
"/urls/update"
)
...
...
@@ -646,7 +646,7 @@ def generate_ollama_embeddings(
class
GenerateCompletionForm
(
BaseModel
):
model
:
str
prompt
:
str
images
:
Optional
[
L
ist
[
str
]]
=
None
images
:
Optional
[
l
ist
[
str
]]
=
None
format
:
Optional
[
str
]
=
None
options
:
Optional
[
dict
]
=
None
system
:
Optional
[
str
]
=
None
...
...
@@ -689,12 +689,12 @@ async def generate_completion(
class
ChatMessage
(
BaseModel
):
role
:
str
content
:
str
images
:
Optional
[
L
ist
[
str
]]
=
None
images
:
Optional
[
l
ist
[
str
]]
=
None
class
GenerateChatCompletionForm
(
BaseModel
):
model
:
str
messages
:
L
ist
[
ChatMessage
]
messages
:
l
ist
[
ChatMessage
]
format
:
Optional
[
str
]
=
None
options
:
Optional
[
dict
]
=
None
template
:
Optional
[
str
]
=
None
...
...
@@ -772,7 +772,7 @@ class OpenAIChatMessage(BaseModel):
class
OpenAIChatCompletionForm
(
BaseModel
):
model
:
str
messages
:
L
ist
[
OpenAIChatMessage
]
messages
:
l
ist
[
OpenAIChatMessage
]
model_config
=
ConfigDict
(
extra
=
"allow"
)
...
...
backend/apps/openai/main.py
View file @
29f904db
...
...
@@ -33,7 +33,7 @@ from config import (
MODEL_FILTER_LIST
,
AppConfig
,
)
from
typing
import
List
,
Optional
,
Literal
,
overload
from
typing
import
Optional
,
Literal
,
overload
import
hashlib
...
...
@@ -89,11 +89,11 @@ async def update_config(form_data: OpenAIConfigForm, user=Depends(get_admin_user
class
UrlsUpdateForm
(
BaseModel
):
urls
:
L
ist
[
str
]
urls
:
l
ist
[
str
]
class
KeysUpdateForm
(
BaseModel
):
keys
:
L
ist
[
str
]
keys
:
l
ist
[
str
]
@
app
.
get
(
"/urls"
)
...
...
backend/apps/rag/main.py
View file @
29f904db
...
...
@@ -13,7 +13,7 @@ import os, shutil, logging, re
from
datetime
import
datetime
from
pathlib
import
Path
from
typing
import
List
,
Union
,
Sequence
,
Iterator
,
Any
from
typing
import
Union
,
Sequence
,
Iterator
,
Any
from
chromadb.utils.batch_utils
import
create_batches
from
langchain_core.documents
import
Document
...
...
@@ -439,7 +439,7 @@ class ChunkParamUpdateForm(BaseModel):
class
YoutubeLoaderConfig
(
BaseModel
):
language
:
L
ist
[
str
]
language
:
l
ist
[
str
]
translation
:
Optional
[
str
]
=
None
...
...
@@ -642,7 +642,7 @@ def query_doc_handler(
class
QueryCollectionsForm
(
BaseModel
):
collection_names
:
L
ist
[
str
]
collection_names
:
l
ist
[
str
]
query
:
str
k
:
Optional
[
int
]
=
None
r
:
Optional
[
float
]
=
None
...
...
@@ -1021,7 +1021,7 @@ class TikaLoader:
self
.
file_path
=
file_path
self
.
mime_type
=
mime_type
def
load
(
self
)
->
L
ist
[
Document
]:
def
load
(
self
)
->
l
ist
[
Document
]:
with
open
(
self
.
file_path
,
"rb"
)
as
f
:
data
=
f
.
read
()
...
...
backend/apps/rag/search/brave.py
View file @
29f904db
import
logging
from
typing
import
List
,
Optional
from
typing
import
Optional
import
requests
from
apps.rag.search.main
import
SearchResult
,
get_filtered_results
...
...
@@ -10,7 +10,7 @@ log.setLevel(SRC_LOG_LEVELS["RAG"])
def
search_brave
(
api_key
:
str
,
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
L
ist
[
str
]]
=
None
api_key
:
str
,
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
l
ist
[
str
]]
=
None
)
->
list
[
SearchResult
]:
"""Search using Brave's Search API and return the results as a list of SearchResult objects.
...
...
backend/apps/rag/search/duckduckgo.py
View file @
29f904db
import
logging
from
typing
import
List
,
Optional
from
typing
import
Optional
from
apps.rag.search.main
import
SearchResult
,
get_filtered_results
from
duckduckgo_search
import
DDGS
from
config
import
SRC_LOG_LEVELS
...
...
@@ -9,7 +9,7 @@ log.setLevel(SRC_LOG_LEVELS["RAG"])
def
search_duckduckgo
(
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
L
ist
[
str
]]
=
None
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
l
ist
[
str
]]
=
None
)
->
list
[
SearchResult
]:
"""
Search using DuckDuckGo's Search API and return the results as a list of SearchResult objects.
...
...
@@ -18,7 +18,7 @@ def search_duckduckgo(
count (int): The number of results to return
Returns:
L
ist[SearchResult]: A list of search results
l
ist[SearchResult]: A list of search results
"""
# Use the DDGS context manager to create a DDGS object
with
DDGS
()
as
ddgs
:
...
...
backend/apps/rag/search/google_pse.py
View file @
29f904db
import
json
import
logging
from
typing
import
List
,
Optional
from
typing
import
Optional
import
requests
from
apps.rag.search.main
import
SearchResult
,
get_filtered_results
...
...
@@ -15,7 +15,7 @@ def search_google_pse(
search_engine_id
:
str
,
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
L
ist
[
str
]]
=
None
,
filter_list
:
Optional
[
l
ist
[
str
]]
=
None
,
)
->
list
[
SearchResult
]:
"""Search using Google's Programmable Search Engine API and return the results as a list of SearchResult objects.
...
...
backend/apps/rag/search/jina_search.py
View file @
29f904db
...
...
@@ -17,7 +17,7 @@ def search_jina(query: str, count: int) -> list[SearchResult]:
count (int): The number of results to return
Returns:
L
ist[SearchResult]: A list of search results
l
ist[SearchResult]: A list of search results
"""
jina_search_endpoint
=
"https://s.jina.ai/"
headers
=
{
...
...
backend/apps/rag/search/searxng.py
View file @
29f904db
import
logging
import
requests
from
typing
import
List
,
Optional
from
typing
import
Optional
from
apps.rag.search.main
import
SearchResult
,
get_filtered_results
from
config
import
SRC_LOG_LEVELS
...
...
@@ -14,9 +14,9 @@ def search_searxng(
query_url
:
str
,
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
L
ist
[
str
]]
=
None
,
filter_list
:
Optional
[
l
ist
[
str
]]
=
None
,
**
kwargs
,
)
->
L
ist
[
SearchResult
]:
)
->
l
ist
[
SearchResult
]:
"""
Search a SearXNG instance for a given query and return the results as a list of SearchResult objects.
...
...
@@ -31,10 +31,10 @@ def search_searxng(
language (str): Language filter for the search results; e.g., "en-US". Defaults to an empty string.
safesearch (int): Safe search filter for safer web results; 0 = off, 1 = moderate, 2 = strict. Defaults to 1 (moderate).
time_range (str): Time range for filtering results by date; e.g., "2023-04-05..today" or "all-time". Defaults to ''.
categories: (Optional[
L
ist[str]]): Specific categories within which the search should be performed, defaulting to an empty string if not provided.
categories: (Optional[
l
ist[str]]): Specific categories within which the search should be performed, defaulting to an empty string if not provided.
Returns:
L
ist[SearchResult]: A list of SearchResults sorted by relevance score in descending order.
l
ist[SearchResult]: A list of SearchResults sorted by relevance score in descending order.
Raise:
requests.exceptions.RequestException: If a request error occurs during the search process.
...
...
backend/apps/rag/search/serper.py
View file @
29f904db
import
json
import
logging
from
typing
import
List
,
Optional
from
typing
import
Optional
import
requests
from
apps.rag.search.main
import
SearchResult
,
get_filtered_results
...
...
@@ -11,7 +11,7 @@ log.setLevel(SRC_LOG_LEVELS["RAG"])
def
search_serper
(
api_key
:
str
,
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
L
ist
[
str
]]
=
None
api_key
:
str
,
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
l
ist
[
str
]]
=
None
)
->
list
[
SearchResult
]:
"""Search using serper.dev's API and return the results as a list of SearchResult objects.
...
...
backend/apps/rag/search/serply.py
View file @
29f904db
import
json
import
logging
from
typing
import
List
,
Optional
from
typing
import
Optional
import
requests
from
urllib.parse
import
urlencode
...
...
@@ -19,7 +19,7 @@ def search_serply(
limit
:
int
=
10
,
device_type
:
str
=
"desktop"
,
proxy_location
:
str
=
"US"
,
filter_list
:
Optional
[
L
ist
[
str
]]
=
None
,
filter_list
:
Optional
[
l
ist
[
str
]]
=
None
,
)
->
list
[
SearchResult
]:
"""Search using serper.dev's API and return the results as a list of SearchResult objects.
...
...
backend/apps/rag/search/serpstack.py
View file @
29f904db
import
json
import
logging
from
typing
import
List
,
Optional
from
typing
import
Optional
import
requests
from
apps.rag.search.main
import
SearchResult
,
get_filtered_results
...
...
@@ -14,7 +14,7 @@ def search_serpstack(
api_key
:
str
,
query
:
str
,
count
:
int
,
filter_list
:
Optional
[
L
ist
[
str
]]
=
None
,
filter_list
:
Optional
[
l
ist
[
str
]]
=
None
,
https_enabled
:
bool
=
True
,
)
->
list
[
SearchResult
]:
"""Search using serpstack.com's and return the results as a list of SearchResult objects.
...
...
backend/apps/rag/search/tavily.py
View file @
29f904db
...
...
@@ -17,7 +17,7 @@ def search_tavily(api_key: str, query: str, count: int) -> list[SearchResult]:
query (str): The query to search for
Returns:
L
ist[SearchResult]: A list of search results
l
ist[SearchResult]: A list of search results
"""
url
=
"https://api.tavily.com/search"
data
=
{
"query"
:
query
,
"api_key"
:
api_key
}
...
...
backend/apps/rag/utils.py
View file @
29f904db
...
...
@@ -2,7 +2,7 @@ import os
import
logging
import
requests
from
typing
import
List
,
Union
from
typing
import
Union
from
apps.ollama.main
import
(
generate_ollama_embeddings
,
...
...
@@ -142,7 +142,7 @@ def merge_and_sort_query_results(query_results, k, reverse=False):
def
query_collection
(
collection_names
:
L
ist
[
str
],
collection_names
:
l
ist
[
str
],
query
:
str
,
embedding_function
,
k
:
int
,
...
...
@@ -163,7 +163,7 @@ def query_collection(
def
query_collection_with_hybrid_search
(
collection_names
:
L
ist
[
str
],
collection_names
:
l
ist
[
str
],
query
:
str
,
embedding_function
,
k
:
int
,
...
...
@@ -411,7 +411,7 @@ class ChromaRetriever(BaseRetriever):
query
:
str
,
*
,
run_manager
:
CallbackManagerForRetrieverRun
,
)
->
L
ist
[
Document
]:
)
->
l
ist
[
Document
]:
query_embeddings
=
self
.
embedding_function
(
query
)
results
=
self
.
collection
.
query
(
...
...
backend/apps/webui/models/chats.py
View file @
29f904db
from
pydantic
import
BaseModel
,
ConfigDict
from
typing
import
List
,
Union
,
Optional
from
typing
import
Union
,
Optional
import
json
import
uuid
...
...
@@ -215,7 +215,7 @@ class ChatTable:
def
get_archived_chat_list_by_user_id
(
self
,
user_id
:
str
,
skip
:
int
=
0
,
limit
:
int
=
50
)
->
L
ist
[
ChatModel
]:
)
->
l
ist
[
ChatModel
]:
with
get_db
()
as
db
:
all_chats
=
(
...
...
@@ -233,7 +233,7 @@ class ChatTable:
include_archived
:
bool
=
False
,
skip
:
int
=
0
,
limit
:
int
=
50
,
)
->
L
ist
[
ChatModel
]:
)
->
l
ist
[
ChatModel
]:
with
get_db
()
as
db
:
query
=
db
.
query
(
Chat
).
filter_by
(
user_id
=
user_id
)
if
not
include_archived
:
...
...
@@ -251,7 +251,7 @@ class ChatTable:
include_archived
:
bool
=
False
,
skip
:
int
=
0
,
limit
:
int
=
-
1
,
)
->
L
ist
[
ChatTitleIdResponse
]:
)
->
l
ist
[
ChatTitleIdResponse
]:
with
get_db
()
as
db
:
query
=
db
.
query
(
Chat
).
filter_by
(
user_id
=
user_id
)
if
not
include_archived
:
...
...
@@ -279,8 +279,8 @@ class ChatTable:
]
def
get_chat_list_by_chat_ids
(
self
,
chat_ids
:
L
ist
[
str
],
skip
:
int
=
0
,
limit
:
int
=
50
)
->
L
ist
[
ChatModel
]:
self
,
chat_ids
:
l
ist
[
str
],
skip
:
int
=
0
,
limit
:
int
=
50
)
->
l
ist
[
ChatModel
]:
with
get_db
()
as
db
:
all_chats
=
(
db
.
query
(
Chat
)
...
...
@@ -322,7 +322,7 @@ class ChatTable:
except
Exception
:
return
None
def
get_chats
(
self
,
skip
:
int
=
0
,
limit
:
int
=
50
)
->
L
ist
[
ChatModel
]:
def
get_chats
(
self
,
skip
:
int
=
0
,
limit
:
int
=
50
)
->
l
ist
[
ChatModel
]:
with
get_db
()
as
db
:
all_chats
=
(
...
...
@@ -332,7 +332,7 @@ class ChatTable:
)
return
[
ChatModel
.
model_validate
(
chat
)
for
chat
in
all_chats
]
def
get_chats_by_user_id
(
self
,
user_id
:
str
)
->
L
ist
[
ChatModel
]:
def
get_chats_by_user_id
(
self
,
user_id
:
str
)
->
l
ist
[
ChatModel
]:
with
get_db
()
as
db
:
all_chats
=
(
...
...
@@ -342,7 +342,7 @@ class ChatTable:
)
return
[
ChatModel
.
model_validate
(
chat
)
for
chat
in
all_chats
]
def
get_archived_chats_by_user_id
(
self
,
user_id
:
str
)
->
L
ist
[
ChatModel
]:
def
get_archived_chats_by_user_id
(
self
,
user_id
:
str
)
->
l
ist
[
ChatModel
]:
with
get_db
()
as
db
:
all_chats
=
(
...
...
backend/apps/webui/models/documents.py
View file @
29f904db
from
pydantic
import
BaseModel
,
ConfigDict
from
typing
import
List
,
Optional
from
typing
import
Optional
import
time
import
logging
...
...
@@ -105,7 +105,7 @@ class DocumentsTable:
except
Exception
:
return
None
def
get_docs
(
self
)
->
L
ist
[
DocumentModel
]:
def
get_docs
(
self
)
->
l
ist
[
DocumentModel
]:
with
get_db
()
as
db
:
return
[
...
...
backend/apps/webui/models/files.py
View file @
29f904db
from
pydantic
import
BaseModel
,
ConfigDict
from
typing
import
List
,
Union
,
Optional
from
typing
import
Union
,
Optional
import
time
import
logging
...
...
@@ -93,7 +93,7 @@ class FilesTable:
except
Exception
:
return
None
def
get_files
(
self
)
->
L
ist
[
FileModel
]:
def
get_files
(
self
)
->
l
ist
[
FileModel
]:
with
get_db
()
as
db
:
return
[
FileModel
.
model_validate
(
file
)
for
file
in
db
.
query
(
File
).
all
()]
...
...
backend/apps/webui/models/functions.py
View file @
29f904db
from
pydantic
import
BaseModel
,
ConfigDict
from
typing
import
List
,
Union
,
Optional
from
typing
import
Union
,
Optional
import
time
import
logging
...
...
@@ -125,7 +125,7 @@ class FunctionsTable:
except
Exception
:
return
None
def
get_functions
(
self
,
active_only
=
False
)
->
L
ist
[
FunctionModel
]:
def
get_functions
(
self
,
active_only
=
False
)
->
l
ist
[
FunctionModel
]:
with
get_db
()
as
db
:
if
active_only
:
...
...
@@ -141,7 +141,7 @@ class FunctionsTable:
def
get_functions_by_type
(
self
,
type
:
str
,
active_only
=
False
)
->
L
ist
[
FunctionModel
]:
)
->
l
ist
[
FunctionModel
]:
with
get_db
()
as
db
:
if
active_only
:
...
...
@@ -157,7 +157,7 @@ class FunctionsTable:
for
function
in
db
.
query
(
Function
).
filter_by
(
type
=
type
).
all
()
]
def
get_global_filter_functions
(
self
)
->
L
ist
[
FunctionModel
]:
def
get_global_filter_functions
(
self
)
->
l
ist
[
FunctionModel
]:
with
get_db
()
as
db
:
return
[
...
...
@@ -167,7 +167,7 @@ class FunctionsTable:
.
all
()
]
def
get_global_action_functions
(
self
)
->
L
ist
[
FunctionModel
]:
def
get_global_action_functions
(
self
)
->
l
ist
[
FunctionModel
]:
with
get_db
()
as
db
:
return
[
FunctionModel
.
model_validate
(
function
)
...
...
backend/apps/webui/models/memories.py
View file @
29f904db
from
pydantic
import
BaseModel
,
ConfigDict
from
typing
import
List
,
Union
,
Optional
from
typing
import
Union
,
Optional
from
sqlalchemy
import
Column
,
String
,
BigInteger
,
Text
...
...
@@ -83,7 +83,7 @@ class MemoriesTable:
except
Exception
:
return
None
def
get_memories
(
self
)
->
L
ist
[
MemoryModel
]:
def
get_memories
(
self
)
->
l
ist
[
MemoryModel
]:
with
get_db
()
as
db
:
try
:
...
...
@@ -92,7 +92,7 @@ class MemoriesTable:
except
Exception
:
return
None
def
get_memories_by_user_id
(
self
,
user_id
:
str
)
->
L
ist
[
MemoryModel
]:
def
get_memories_by_user_id
(
self
,
user_id
:
str
)
->
l
ist
[
MemoryModel
]:
with
get_db
()
as
db
:
try
:
...
...
backend/apps/webui/models/models.py
View file @
29f904db
...
...
@@ -137,7 +137,7 @@ class ModelsTable:
print
(
e
)
return
None
def
get_all_models
(
self
)
->
L
ist
[
ModelModel
]:
def
get_all_models
(
self
)
->
l
ist
[
ModelModel
]:
with
get_db
()
as
db
:
return
[
ModelModel
.
model_validate
(
model
)
for
model
in
db
.
query
(
Model
).
all
()]
...
...
Prev
1
2
Next
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