Merge pull request #8222 from open-webui/dev

dev
This commit is contained in:
Timothy Jaeryang Baek 2024-12-30 17:55:13 -08:00 committed by GitHub
commit 4b0fa112bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 54 additions and 42 deletions

View File

@ -520,6 +520,7 @@ async def reset_knowledge_by_id(id: str, user=Depends(get_verified_user)):
@router.post("/{id}/files/batch/add", response_model=Optional[KnowledgeFilesResponse]) @router.post("/{id}/files/batch/add", response_model=Optional[KnowledgeFilesResponse])
def add_files_to_knowledge_batch( def add_files_to_knowledge_batch(
request: Request,
id: str, id: str,
form_data: list[KnowledgeFileIdForm], form_data: list[KnowledgeFileIdForm],
user=Depends(get_verified_user), user=Depends(get_verified_user),
@ -555,7 +556,9 @@ def add_files_to_knowledge_batch(
# Process files # Process files
try: try:
result = process_files_batch( result = process_files_batch(
BatchProcessFilesForm(files=files, collection_name=id) request=request,
form_data=BatchProcessFilesForm(files=files, collection_name=id),
user=user,
) )
except Exception as e: except Exception as e:
log.error( log.error(

View File

@ -1458,6 +1458,7 @@ class BatchProcessFilesResponse(BaseModel):
@router.post("/process/files/batch") @router.post("/process/files/batch")
def process_files_batch( def process_files_batch(
request: Request,
form_data: BatchProcessFilesForm, form_data: BatchProcessFilesForm,
user=Depends(get_verified_user), user=Depends(get_verified_user),
) -> BatchProcessFilesResponse: ) -> BatchProcessFilesResponse:
@ -1504,7 +1505,10 @@ def process_files_batch(
if all_docs: if all_docs:
try: try:
save_docs_to_vector_db( save_docs_to_vector_db(
docs=all_docs, collection_name=collection_name, add=True request=request,
docs=all_docs,
collection_name=collection_name,
add=True,
) )
# Update all files with collection name # Update all files with collection name

View File

@ -23,7 +23,7 @@ from open_webui.models.users import Users
from open_webui.socket.main import ( from open_webui.socket.main import (
get_event_call, get_event_call,
get_event_emitter, get_event_emitter,
get_user_id_from_session_pool, get_active_status_by_user_id,
) )
from open_webui.routers.tasks import ( from open_webui.routers.tasks import (
generate_queries, generate_queries,
@ -750,7 +750,7 @@ async def process_chat_response(
): ):
async def background_tasks_handler(): async def background_tasks_handler():
message_map = Chats.get_messages_by_chat_id(metadata["chat_id"]) message_map = Chats.get_messages_by_chat_id(metadata["chat_id"])
message = message_map.get(metadata["message_id"]) message = message_map.get(metadata["message_id"]) if message_map else None
if message: if message:
messages = get_message_list(message_map, message.get("id")) messages = get_message_list(message_map, message.get("id"))
@ -896,7 +896,7 @@ async def process_chat_response(
) )
# Send a webhook notification if the user is not active # Send a webhook notification if the user is not active
if get_user_id_from_session_pool(metadata["session_id"]) is None: if get_active_status_by_user_id(user.id) is None:
webhook_url = Users.get_user_webhook_url_by_id(user.id) webhook_url = Users.get_user_webhook_url_by_id(user.id)
if webhook_url: if webhook_url:
post_webhook( post_webhook(
@ -1002,11 +1002,22 @@ async def process_chat_response(
"content": content, "content": content,
} }
await event_emitter(
{
"type": "chat:completion",
"data": data,
}
)
except Exception as e: except Exception as e:
done = "data: [DONE]" in line done = "data: [DONE]" in line
title = Chats.get_chat_title_by_id(metadata["chat_id"])
if done: if done:
pass
else:
continue
title = Chats.get_chat_title_by_id(metadata["chat_id"])
data = {"done": True, "content": content, "title": title} data = {"done": True, "content": content, "title": title}
if not ENABLE_REALTIME_CHAT_SAVE: if not ENABLE_REALTIME_CHAT_SAVE:
@ -1020,10 +1031,7 @@ async def process_chat_response(
) )
# Send a webhook notification if the user is not active # Send a webhook notification if the user is not active
if ( if get_active_status_by_user_id(user.id) is None:
get_user_id_from_session_pool(metadata["session_id"])
is None
):
webhook_url = Users.get_user_webhook_url_by_id(user.id) webhook_url = Users.get_user_webhook_url_by_id(user.id)
if webhook_url: if webhook_url:
post_webhook( post_webhook(
@ -1037,9 +1045,6 @@ async def process_chat_response(
}, },
) )
else:
continue
await event_emitter( await event_emitter(
{ {
"type": "chat:completion", "type": "chat:completion",

View File

@ -29,7 +29,7 @@ async def convert_streaming_response_ollama_to_openai(ollama_streaming_response)
( (
( (
data.get("eval_count", 0) data.get("eval_count", 0)
/ ((data.get("eval_duration", 0) / 1_000_000)) / ((data.get("eval_duration", 0) / 10_000_000))
) )
* 100 * 100
), ),
@ -43,7 +43,7 @@ async def convert_streaming_response_ollama_to_openai(ollama_streaming_response)
( (
( (
data.get("prompt_eval_count", 0) data.get("prompt_eval_count", 0)
/ ((data.get("prompt_eval_duration", 0) / 1_000_000)) / ((data.get("prompt_eval_duration", 0) / 10_000_000))
) )
* 100 * 100
), ),