mirror of
https://github.com/open-webui/open-webui
synced 2025-06-12 09:23:05 +00:00
refac
This commit is contained in:
parent
1197c640c4
commit
9a081c8593
@ -812,6 +812,8 @@ async def chat_completion(
|
|||||||
user=Depends(get_verified_user),
|
user=Depends(get_verified_user),
|
||||||
bypass_filter: bool = False,
|
bypass_filter: bool = False,
|
||||||
):
|
):
|
||||||
|
if not request.app.state.MODELS:
|
||||||
|
await get_all_models(request)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
model_id = form_data.get("model", None)
|
model_id = form_data.get("model", None)
|
||||||
|
@ -21,7 +21,7 @@ from open_webui.env import SRC_LOG_LEVELS
|
|||||||
from open_webui.constants import ERROR_MESSAGES
|
from open_webui.constants import ERROR_MESSAGES
|
||||||
|
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, File, HTTPException, UploadFile, status
|
from fastapi import APIRouter, Depends, File, HTTPException, UploadFile, status, Request
|
||||||
from fastapi.responses import FileResponse, StreamingResponse
|
from fastapi.responses import FileResponse, StreamingResponse
|
||||||
|
|
||||||
|
|
||||||
@ -39,7 +39,9 @@ router = APIRouter()
|
|||||||
|
|
||||||
|
|
||||||
@router.post("/", response_model=FileModelResponse)
|
@router.post("/", response_model=FileModelResponse)
|
||||||
def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)):
|
def upload_file(
|
||||||
|
request: Request, file: UploadFile = File(...), user=Depends(get_verified_user)
|
||||||
|
):
|
||||||
log.info(f"file.content_type: {file.content_type}")
|
log.info(f"file.content_type: {file.content_type}")
|
||||||
try:
|
try:
|
||||||
unsanitized_filename = file.filename
|
unsanitized_filename = file.filename
|
||||||
@ -68,7 +70,7 @@ def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process_file(ProcessFileForm(file_id=id))
|
process_file(request, ProcessFileForm(file_id=id))
|
||||||
file_item = Files.get_file_by_id(id=id)
|
file_item = Files.get_file_by_id(id=id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
@ -183,13 +185,15 @@ class ContentForm(BaseModel):
|
|||||||
|
|
||||||
@router.post("/{id}/data/content/update")
|
@router.post("/{id}/data/content/update")
|
||||||
async def update_file_data_content_by_id(
|
async def update_file_data_content_by_id(
|
||||||
id: str, form_data: ContentForm, user=Depends(get_verified_user)
|
request: Request, id: str, form_data: ContentForm, user=Depends(get_verified_user)
|
||||||
):
|
):
|
||||||
file = Files.get_file_by_id(id)
|
file = Files.get_file_by_id(id)
|
||||||
|
|
||||||
if file and (file.user_id == user.id or user.role == "admin"):
|
if file and (file.user_id == user.id or user.role == "admin"):
|
||||||
try:
|
try:
|
||||||
process_file(ProcessFileForm(file_id=id, content=form_data.content))
|
process_file(
|
||||||
|
request, ProcessFileForm(file_id=id, content=form_data.content)
|
||||||
|
)
|
||||||
file = Files.get_file_by_id(id=id)
|
file = Files.get_file_by_id(id=id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
@ -242,6 +242,7 @@ class KnowledgeFileIdForm(BaseModel):
|
|||||||
|
|
||||||
@router.post("/{id}/file/add", response_model=Optional[KnowledgeFilesResponse])
|
@router.post("/{id}/file/add", response_model=Optional[KnowledgeFilesResponse])
|
||||||
def add_file_to_knowledge_by_id(
|
def add_file_to_knowledge_by_id(
|
||||||
|
request: Request,
|
||||||
id: str,
|
id: str,
|
||||||
form_data: KnowledgeFileIdForm,
|
form_data: KnowledgeFileIdForm,
|
||||||
user=Depends(get_verified_user),
|
user=Depends(get_verified_user),
|
||||||
@ -274,7 +275,9 @@ def add_file_to_knowledge_by_id(
|
|||||||
|
|
||||||
# Add content to the vector database
|
# Add content to the vector database
|
||||||
try:
|
try:
|
||||||
process_file(ProcessFileForm(file_id=form_data.file_id, collection_name=id))
|
process_file(
|
||||||
|
request, ProcessFileForm(file_id=form_data.file_id, collection_name=id)
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug(e)
|
log.debug(e)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@ -318,6 +321,7 @@ def add_file_to_knowledge_by_id(
|
|||||||
|
|
||||||
@router.post("/{id}/file/update", response_model=Optional[KnowledgeFilesResponse])
|
@router.post("/{id}/file/update", response_model=Optional[KnowledgeFilesResponse])
|
||||||
def update_file_from_knowledge_by_id(
|
def update_file_from_knowledge_by_id(
|
||||||
|
request: Request,
|
||||||
id: str,
|
id: str,
|
||||||
form_data: KnowledgeFileIdForm,
|
form_data: KnowledgeFileIdForm,
|
||||||
user=Depends(get_verified_user),
|
user=Depends(get_verified_user),
|
||||||
@ -349,7 +353,9 @@ def update_file_from_knowledge_by_id(
|
|||||||
|
|
||||||
# Add content to the vector database
|
# Add content to the vector database
|
||||||
try:
|
try:
|
||||||
process_file(ProcessFileForm(file_id=form_data.file_id, collection_name=id))
|
process_file(
|
||||||
|
request, ProcessFileForm(file_id=form_data.file_id, collection_name=id)
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
Loading…
Reference in New Issue
Block a user