mirror of
https://github.com/open-webui/open-webui
synced 2025-03-16 10:28:28 +00:00
enh: ENABLE_REALTIME_CHAT_SAVE
Some checks are pending
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Python CI / Format Backend (3.11) (push) Waiting to run
Frontend Build / Format & Build Frontend (push) Waiting to run
Frontend Build / Frontend Unit Tests (push) Waiting to run
Integration Test / Run Cypress Integration Tests (push) Waiting to run
Integration Test / Run Migration Tests (push) Waiting to run
Some checks are pending
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Python CI / Format Backend (3.11) (push) Waiting to run
Frontend Build / Format & Build Frontend (push) Waiting to run
Frontend Build / Frontend Unit Tests (push) Waiting to run
Integration Test / Run Cypress Integration Tests (push) Waiting to run
Integration Test / Run Migration Tests (push) Waiting to run
This commit is contained in:
parent
c8fb11db59
commit
d55884b50e
@ -311,6 +311,11 @@ RESET_CONFIG_ON_START = (
|
|||||||
os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true"
|
os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
ENABLE_REALTIME_CHAT_SAVE = (
|
||||||
|
os.environ.get("ENABLE_REALTIME_CHAT_SAVE", "True").lower() == "true"
|
||||||
|
)
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# REDIS
|
# REDIS
|
||||||
####################################
|
####################################
|
||||||
|
@ -65,6 +65,7 @@ from open_webui.env import (
|
|||||||
SRC_LOG_LEVELS,
|
SRC_LOG_LEVELS,
|
||||||
GLOBAL_LOG_LEVEL,
|
GLOBAL_LOG_LEVEL,
|
||||||
BYPASS_MODEL_ACCESS_CONTROL,
|
BYPASS_MODEL_ACCESS_CONTROL,
|
||||||
|
ENABLE_REALTIME_CHAT_SAVE,
|
||||||
)
|
)
|
||||||
from open_webui.constants import TASKS
|
from open_webui.constants import TASKS
|
||||||
|
|
||||||
@ -977,7 +978,6 @@ async def process_chat_response(
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
value = (
|
value = (
|
||||||
data.get("choices", [])[0]
|
data.get("choices", [])[0]
|
||||||
.get("delta", {})
|
.get("delta", {})
|
||||||
@ -987,6 +987,28 @@ async def process_chat_response(
|
|||||||
if value:
|
if value:
|
||||||
content = f"{content}{value}"
|
content = f"{content}{value}"
|
||||||
|
|
||||||
|
if ENABLE_REALTIME_CHAT_SAVE:
|
||||||
|
# Save message in the database
|
||||||
|
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||||
|
metadata["chat_id"],
|
||||||
|
metadata["message_id"],
|
||||||
|
{
|
||||||
|
"content": content,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
data = {
|
||||||
|
"content": content,
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
done = "data: [DONE]" in line
|
||||||
|
title = Chats.get_chat_title_by_id(metadata["chat_id"])
|
||||||
|
|
||||||
|
if done:
|
||||||
|
data = {"done": True, "content": content, "title": title}
|
||||||
|
|
||||||
|
if not ENABLE_REALTIME_CHAT_SAVE:
|
||||||
# Save message in the database
|
# Save message in the database
|
||||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||||
metadata["chat_id"],
|
metadata["chat_id"],
|
||||||
@ -996,13 +1018,6 @@ async def process_chat_response(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
done = "data: [DONE]" in line
|
|
||||||
title = Chats.get_chat_title_by_id(metadata["chat_id"])
|
|
||||||
|
|
||||||
if done:
|
|
||||||
data = {"done": True, "content": content, "title": title}
|
|
||||||
|
|
||||||
# Send a webhook notification if the user is not active
|
# Send a webhook notification if the user is not active
|
||||||
if (
|
if (
|
||||||
get_user_id_from_session_pool(metadata["session_id"])
|
get_user_id_from_session_pool(metadata["session_id"])
|
||||||
|
@ -1053,7 +1053,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const chatCompletionEventHandler = async (data, message, chatId) => {
|
const chatCompletionEventHandler = async (data, message, chatId) => {
|
||||||
const { id, done, choices, sources, selected_model_id, error, usage } = data;
|
const { id, done, choices, content, sources, selected_model_id, error, usage } = data;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
await handleOpenAIError(error, message);
|
await handleOpenAIError(error, message);
|
||||||
@ -1105,6 +1105,38 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (content) {
|
||||||
|
// REALTIME_CHAT_SAVE is disabled
|
||||||
|
message.content = content;
|
||||||
|
|
||||||
|
if (navigator.vibrate && ($settings?.hapticFeedback ?? false)) {
|
||||||
|
navigator.vibrate(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit chat event for TTS
|
||||||
|
const messageContentParts = getMessageContentParts(
|
||||||
|
message.content,
|
||||||
|
$config?.audio?.tts?.split_on ?? 'punctuation'
|
||||||
|
);
|
||||||
|
messageContentParts.pop();
|
||||||
|
|
||||||
|
// dispatch only last sentence and make sure it hasn't been dispatched before
|
||||||
|
if (
|
||||||
|
messageContentParts.length > 0 &&
|
||||||
|
messageContentParts[messageContentParts.length - 1] !== message.lastSentence
|
||||||
|
) {
|
||||||
|
message.lastSentence = messageContentParts[messageContentParts.length - 1];
|
||||||
|
eventTarget.dispatchEvent(
|
||||||
|
new CustomEvent('chat', {
|
||||||
|
detail: {
|
||||||
|
id: message.id,
|
||||||
|
content: messageContentParts[messageContentParts.length - 1]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (selected_model_id) {
|
if (selected_model_id) {
|
||||||
message.selectedModelId = selected_model_id;
|
message.selectedModelId = selected_model_id;
|
||||||
message.arena = true;
|
message.arena = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user