"git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "3b112375eefe263ab726a5bc51d7884562f4013c"
Commit 29f904db authored by Michael Poluektov's avatar Michael Poluektov
Browse files

remove List imports

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