This commit is contained in:
Timothy Jaeryang Baek 2024-12-30 15:39:35 -08:00
parent 79ce6e0a3f
commit 947f5600d6

View File

@ -23,7 +23,7 @@ from open_webui.models.users import Users
from open_webui.socket.main import (
get_event_call,
get_event_emitter,
get_user_id_from_session_pool,
get_active_status_by_user_id,
)
from open_webui.routers.tasks import (
generate_queries,
@ -896,7 +896,7 @@ async def process_chat_response(
)
# 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)
if webhook_url:
post_webhook(
@ -1002,11 +1002,22 @@ async def process_chat_response(
"content": content,
}
await event_emitter(
{
"type": "chat:completion",
"data": data,
}
)
except Exception as e:
done = "data: [DONE]" in line
title = Chats.get_chat_title_by_id(metadata["chat_id"])
if done:
pass
else:
continue
title = Chats.get_chat_title_by_id(metadata["chat_id"])
data = {"done": True, "content": content, "title": title}
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
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)
if webhook_url:
post_webhook(
@ -1037,9 +1045,6 @@ async def process_chat_response(
},
)
else:
continue
await event_emitter(
{
"type": "chat:completion",