refac: async db
This commit is contained in:
@@ -936,7 +936,7 @@ def apply_source_context_to_messages(
|
||||
)
|
||||
|
||||
|
||||
def process_tool_result(
|
||||
async def process_tool_result(
|
||||
request,
|
||||
tool_function_name,
|
||||
tool_result,
|
||||
@@ -1075,7 +1075,7 @@ def process_tool_result(
|
||||
pass
|
||||
tool_response.append(text)
|
||||
elif item.get('type') in ['image', 'audio']:
|
||||
file_url = get_file_url_from_base64(
|
||||
file_url = await get_file_url_from_base64(
|
||||
request,
|
||||
f'data:{item.get("mimeType")};base64,{item.get("data", item.get("blob", ""))}',
|
||||
{
|
||||
@@ -1304,7 +1304,7 @@ async def chat_completion_tools_handler(
|
||||
except Exception as e:
|
||||
tool_result = str(e)
|
||||
|
||||
tool_result, tool_result_files, tool_result_embeds = process_tool_result(
|
||||
tool_result, tool_result_files, tool_result_embeds = await process_tool_result(
|
||||
request,
|
||||
tool_function_name,
|
||||
tool_result,
|
||||
@@ -1602,7 +1602,7 @@ def get_images_from_messages(message_list):
|
||||
return images
|
||||
|
||||
|
||||
def get_image_urls(delta_images, request, metadata, user) -> list[str]:
|
||||
async def get_image_urls(delta_images, request, metadata, user) -> list[str]:
|
||||
if not isinstance(delta_images, list):
|
||||
return []
|
||||
|
||||
@@ -1616,21 +1616,21 @@ def get_image_urls(delta_images, request, metadata, user) -> list[str]:
|
||||
continue
|
||||
|
||||
if url.startswith('data:image/png;base64'):
|
||||
url = get_image_url_from_base64(request, url, metadata, user)
|
||||
url = await get_image_url_from_base64(request, url, metadata, user)
|
||||
|
||||
image_urls.append(url)
|
||||
|
||||
return image_urls
|
||||
|
||||
|
||||
def add_file_context(messages: list, chat_id: str, user) -> list:
|
||||
async def add_file_context(messages: list, chat_id: str, user) -> list:
|
||||
"""
|
||||
Add file URLs to messages for native function calling.
|
||||
"""
|
||||
if not chat_id or chat_id.startswith('local:'):
|
||||
return messages
|
||||
|
||||
chat = Chats.get_chat_by_id_and_user_id(chat_id, user.id)
|
||||
chat = await Chats.get_chat_by_id_and_user_id(chat_id, user.id)
|
||||
if not chat:
|
||||
return messages
|
||||
|
||||
@@ -1686,7 +1686,7 @@ async def chat_image_generation_handler(request: Request, form_data: dict, extra
|
||||
if chat_id.startswith('local:'):
|
||||
message_list = form_data.get('messages', [])
|
||||
else:
|
||||
chat = Chats.get_chat_by_id_and_user_id(chat_id, user.id)
|
||||
chat = await Chats.get_chat_by_id_and_user_id(chat_id, user.id)
|
||||
await __event_emitter__(
|
||||
{
|
||||
'type': 'status',
|
||||
@@ -2066,12 +2066,12 @@ async def convert_url_images_to_base64(form_data):
|
||||
return form_data
|
||||
|
||||
|
||||
def load_messages_from_db(chat_id: str, message_id: str) -> Optional[list[dict]]:
|
||||
async def load_messages_from_db(chat_id: str, message_id: str) -> Optional[list[dict]]:
|
||||
"""
|
||||
Load the message chain from DB up to message_id,
|
||||
keeping only LLM-relevant fields (role, content, output).
|
||||
"""
|
||||
messages_map = Chats.get_messages_map_by_chat_id(chat_id)
|
||||
messages_map = await Chats.get_messages_map_by_chat_id(chat_id)
|
||||
if not messages_map:
|
||||
return None
|
||||
|
||||
@@ -2149,7 +2149,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
parent_message_id = metadata.get('parent_message_id')
|
||||
|
||||
if chat_id and parent_message_id and not chat_id.startswith('local:'):
|
||||
db_messages = load_messages_from_db(chat_id, parent_message_id)
|
||||
db_messages = await load_messages_from_db(chat_id, parent_message_id)
|
||||
if db_messages:
|
||||
system_message = get_system_message(form_data.get('messages', []))
|
||||
form_data['messages'] = [system_message, *db_messages] if system_message else db_messages
|
||||
@@ -2192,8 +2192,8 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
|
||||
form_data = await convert_url_images_to_base64(form_data)
|
||||
|
||||
event_emitter = get_event_emitter(metadata)
|
||||
event_caller = get_event_call(metadata)
|
||||
event_emitter = await get_event_emitter(metadata)
|
||||
event_caller = await get_event_call(metadata)
|
||||
|
||||
extra_params = {
|
||||
'__event_emitter__': event_emitter,
|
||||
@@ -2231,14 +2231,14 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
chat_id = metadata.get('chat_id', None)
|
||||
folder_id = None
|
||||
if chat_id and user:
|
||||
folder_id = Chats.get_chat_folder_id(chat_id, user.id)
|
||||
folder_id = await Chats.get_chat_folder_id(chat_id, user.id)
|
||||
|
||||
# Fallback: use folder_id from metadata (temporary chats have no DB record)
|
||||
if not folder_id:
|
||||
folder_id = metadata.get('folder_id', None)
|
||||
|
||||
if folder_id and user:
|
||||
folder = Folders.get_folder_by_id_and_user_id(folder_id, user.id)
|
||||
folder = await Folders.get_folder_by_id_and_user_id(folder_id, user.id)
|
||||
|
||||
if folder and folder.data:
|
||||
if 'system_prompt' in folder.data:
|
||||
@@ -2305,8 +2305,8 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
raise e
|
||||
|
||||
try:
|
||||
filter_ids = get_sorted_filter_ids(request, model, metadata.get('filter_ids', []))
|
||||
filter_functions = Functions.get_functions_by_ids(filter_ids)
|
||||
filter_ids = await get_sorted_filter_ids(request, model, metadata.get('filter_ids', []))
|
||||
filter_functions = await Functions.get_functions_by_ids(filter_ids)
|
||||
|
||||
form_data, flags = await process_filter_functions(
|
||||
request=request,
|
||||
@@ -2399,12 +2399,13 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
if all_skill_ids:
|
||||
from open_webui.models.skills import Skills as SkillsModel
|
||||
|
||||
accessible_skill_ids = {s.id for s in SkillsModel.get_skills_by_user_id(user.id, 'read')}
|
||||
available_skills = [
|
||||
s
|
||||
for sid in all_skill_ids
|
||||
if sid in accessible_skill_ids and (s := SkillsModel.get_skill_by_id(sid)) and s.is_active
|
||||
]
|
||||
accessible_skill_ids = {s.id for s in await SkillsModel.get_skills_by_user_id(user.id, 'read')}
|
||||
available_skills = []
|
||||
for sid in all_skill_ids:
|
||||
if sid in accessible_skill_ids:
|
||||
s = await SkillsModel.get_skill_by_id(sid)
|
||||
if s and s.is_active:
|
||||
available_skills.append(s)
|
||||
|
||||
skill_descriptions = ''
|
||||
for skill in available_skills:
|
||||
@@ -2441,7 +2442,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
# Get folder files
|
||||
folder_id = file_item.get('id', None)
|
||||
if folder_id:
|
||||
folder = Folders.get_folder_by_id_and_user_id(folder_id, user.id)
|
||||
folder = await Folders.get_folder_by_id_and_user_id(folder_id, user.id)
|
||||
if folder and folder.data and 'files' in folder.data:
|
||||
files = [f for f in files if f.get('id', None) != folder_id]
|
||||
files = [*files, *folder.data['files']]
|
||||
@@ -2495,7 +2496,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
continue
|
||||
|
||||
# Check access control for MCP server
|
||||
if not has_connection_access(user, mcp_server_connection):
|
||||
if not await has_connection_access(user, mcp_server_connection):
|
||||
log.warning(f'Access denied to MCP server {server_id} for user {user.id}')
|
||||
continue
|
||||
|
||||
@@ -2556,7 +2557,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
tool_specs = await mcp_clients[server_id].list_tool_specs()
|
||||
for tool_spec in tool_specs:
|
||||
|
||||
def make_tool_function(client, function_name):
|
||||
async def make_tool_function(client, function_name):
|
||||
async def tool_function(**kwargs):
|
||||
return await client.call_tool(
|
||||
function_name,
|
||||
@@ -2570,7 +2571,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
# Skip this function
|
||||
continue
|
||||
|
||||
tool_function = make_tool_function(mcp_clients[server_id], tool_spec['name'])
|
||||
tool_function = await make_tool_function(mcp_clients[server_id], tool_spec['name'])
|
||||
|
||||
mcp_tools_dict[f'{server_id}_{tool_spec["name"]}'] = {
|
||||
'spec': {
|
||||
@@ -2664,8 +2665,8 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
if metadata.get('params', {}).get('function_calling') == 'native' and builtin_tools_enabled:
|
||||
# Add file context to user messages
|
||||
chat_id = metadata.get('chat_id')
|
||||
form_data['messages'] = add_file_context(form_data.get('messages', []), chat_id, user)
|
||||
builtin_tools = get_builtin_tools(
|
||||
form_data['messages'] = await add_file_context(form_data.get('messages', []), chat_id, user)
|
||||
builtin_tools = await get_builtin_tools(
|
||||
request,
|
||||
{
|
||||
**extra_params,
|
||||
@@ -2755,7 +2756,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
return form_data, metadata, events
|
||||
|
||||
|
||||
def get_event_emitter_and_caller(metadata):
|
||||
async def get_event_emitter_and_caller(metadata):
|
||||
event_emitter = None
|
||||
event_caller = None
|
||||
|
||||
@@ -2763,18 +2764,18 @@ def get_event_emitter_and_caller(metadata):
|
||||
# It broadcasts to user:{user_id} room AND persists to DB,
|
||||
# so it works for backend-initiated calls (automations, API).
|
||||
if metadata.get('chat_id') and metadata.get('message_id'):
|
||||
event_emitter = get_event_emitter(metadata)
|
||||
event_emitter = await get_event_emitter(metadata)
|
||||
|
||||
# event_caller needs session_id — it calls back to a specific
|
||||
# websocket session (used by direct tools, pyodide code interpreter).
|
||||
if metadata.get('session_id') and metadata.get('chat_id') and metadata.get('message_id'):
|
||||
event_caller = get_event_call(metadata)
|
||||
event_caller = await get_event_call(metadata)
|
||||
|
||||
return event_emitter, event_caller
|
||||
|
||||
|
||||
def build_chat_response_context(request, form_data, user, model, metadata, tasks, events):
|
||||
event_emitter, event_caller = get_event_emitter_and_caller(metadata)
|
||||
async def build_chat_response_context(request, form_data, user, model, metadata, tasks, events):
|
||||
event_emitter, event_caller = await get_event_emitter_and_caller(metadata)
|
||||
return {
|
||||
'request': request,
|
||||
'form_data': form_data,
|
||||
@@ -2862,7 +2863,7 @@ async def background_tasks_handler(ctx):
|
||||
messages = []
|
||||
|
||||
if 'chat_id' in metadata and not metadata['chat_id'].startswith('local:'):
|
||||
messages_map = Chats.get_messages_map_by_chat_id(metadata['chat_id'])
|
||||
messages_map = await Chats.get_messages_map_by_chat_id(metadata['chat_id'])
|
||||
message = messages_map.get(metadata['message_id']) if messages_map else None
|
||||
|
||||
message_list = get_message_list(messages_map, metadata['message_id'])
|
||||
@@ -2942,7 +2943,7 @@ async def background_tasks_handler(ctx):
|
||||
)
|
||||
|
||||
if not metadata.get('chat_id', '').startswith('local:'):
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -2995,7 +2996,7 @@ async def background_tasks_handler(ctx):
|
||||
if not title:
|
||||
title = messages[0].get('content', user_message)
|
||||
|
||||
Chats.update_chat_title_by_id(metadata['chat_id'], title)
|
||||
await Chats.update_chat_title_by_id(metadata['chat_id'], title)
|
||||
|
||||
await event_emitter(
|
||||
{
|
||||
@@ -3007,7 +3008,7 @@ async def background_tasks_handler(ctx):
|
||||
if title == None and len(messages) == 2 and (not messages_map or len(messages_map) <= 2):
|
||||
title = messages[0].get('content', user_message)
|
||||
|
||||
Chats.update_chat_title_by_id(metadata['chat_id'], title)
|
||||
await Chats.update_chat_title_by_id(metadata['chat_id'], title)
|
||||
|
||||
await event_emitter(
|
||||
{
|
||||
@@ -3041,7 +3042,7 @@ async def background_tasks_handler(ctx):
|
||||
|
||||
try:
|
||||
tags = json.loads(tags_string).get('tags', [])
|
||||
Chats.update_chat_tags_by_id(metadata['chat_id'], tags, user)
|
||||
await Chats.update_chat_tags_by_id(metadata['chat_id'], tags, user)
|
||||
|
||||
await event_emitter(
|
||||
{
|
||||
@@ -3076,7 +3077,7 @@ async def non_streaming_chat_response_handler(response, ctx):
|
||||
else:
|
||||
error = str(error)
|
||||
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -3092,7 +3093,7 @@ async def non_streaming_chat_response_handler(response, ctx):
|
||||
)
|
||||
|
||||
if 'selected_model_id' in response_data:
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -3112,7 +3113,7 @@ async def non_streaming_chat_response_handler(response, ctx):
|
||||
}
|
||||
)
|
||||
|
||||
title = Chats.get_chat_title_by_id(metadata['chat_id'])
|
||||
title = await Chats.get_chat_title_by_id(metadata['chat_id'])
|
||||
|
||||
# Use output from backend if provided (OR-compliant backends),
|
||||
# otherwise generate from response content
|
||||
@@ -3143,7 +3144,7 @@ async def non_streaming_chat_response_handler(response, ctx):
|
||||
# Save message in the database
|
||||
usage = normalize_usage(response_data.get('usage', {}) or {})
|
||||
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -3156,8 +3157,8 @@ async def non_streaming_chat_response_handler(response, ctx):
|
||||
)
|
||||
|
||||
# Send a webhook notification if the user is not active
|
||||
if request.app.state.config.ENABLE_USER_WEBHOOKS and not Users.is_user_active(user.id):
|
||||
webhook_url = Users.get_user_webhook_url_by_id(user.id)
|
||||
if request.app.state.config.ENABLE_USER_WEBHOOKS and not await Users.is_user_active(user.id):
|
||||
webhook_url = await Users.get_user_webhook_url_by_id(user.id)
|
||||
if webhook_url:
|
||||
await post_webhook(
|
||||
request.app.state.WEBUI_NAME,
|
||||
@@ -3211,8 +3212,8 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
}
|
||||
|
||||
filter_functions = [
|
||||
Functions.get_function_by_id(filter_id)
|
||||
for filter_id in get_sorted_filter_ids(request, model, metadata.get('filter_ids', []))
|
||||
await Functions.get_function_by_id(filter_id)
|
||||
for filter_id in await get_sorted_filter_ids(request, model, metadata.get('filter_ids', []))
|
||||
]
|
||||
|
||||
# Standard streaming response handler
|
||||
@@ -3447,7 +3448,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
|
||||
return output, end_flag
|
||||
|
||||
message = Chats.get_message_by_id_and_message_id(metadata['chat_id'], metadata['message_id'])
|
||||
message = await Chats.get_message_by_id_and_message_id(metadata['chat_id'], metadata['message_id'])
|
||||
|
||||
tool_calls = []
|
||||
|
||||
@@ -3509,7 +3510,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
)
|
||||
|
||||
# Save message in the database
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -3579,7 +3580,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
|
||||
if 'selected_model_id' in data:
|
||||
model_id = data['selected_model_id']
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -3645,7 +3646,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
error = data.get('error', {})
|
||||
if error:
|
||||
try:
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -3762,10 +3763,10 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
}
|
||||
)
|
||||
|
||||
image_urls = get_image_urls(delta.get('images', []), request, metadata, user)
|
||||
image_urls = await get_image_urls(delta.get('images', []), request, metadata, user)
|
||||
if image_urls:
|
||||
image_file_list = [{'type': 'image', 'url': url} for url in image_urls]
|
||||
message_files = Chats.add_message_files_by_id_and_message_id(
|
||||
message_files = await Chats.add_message_files_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
image_file_list,
|
||||
@@ -3847,7 +3848,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
)
|
||||
|
||||
if ENABLE_CHAT_RESPONSE_BASE64_IMAGE_URL_CONVERSION:
|
||||
value = convert_markdown_base64_images(
|
||||
value = await convert_markdown_base64_images(
|
||||
request,
|
||||
value,
|
||||
{
|
||||
@@ -3963,7 +3964,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
|
||||
if ENABLE_REALTIME_CHAT_SAVE:
|
||||
# Save message in the database
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -4184,7 +4185,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
)
|
||||
|
||||
else:
|
||||
tool_function = get_updated_tool_function(
|
||||
tool_function = await get_updated_tool_function(
|
||||
function=tool['callable'],
|
||||
extra_params={
|
||||
'__messages__': form_data.get('messages', []),
|
||||
@@ -4197,7 +4198,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
except Exception as e:
|
||||
tool_result = str(e)
|
||||
|
||||
tool_result, tool_result_files, tool_result_embeds = process_tool_result(
|
||||
tool_result, tool_result_files, tool_result_embeds = await process_tool_result(
|
||||
request,
|
||||
tool_function_name,
|
||||
tool_result,
|
||||
@@ -4487,7 +4488,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
BLOCKED_MODULES = {CODE_INTERPRETER_BLOCKED_MODULES}
|
||||
|
||||
_real_import = builtins.__import__
|
||||
def restricted_import(name, globals=None, locals=None, fromlist=(), level=0):
|
||||
async def restricted_import(name, globals=None, locals=None, fromlist=(), level=0):
|
||||
if name.split('.')[0] in BLOCKED_MODULES:
|
||||
importer_name = globals.get('__name__') if globals else None
|
||||
if importer_name == '__main__':
|
||||
@@ -4541,7 +4542,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
stdoutLines = stdout.split('\n')
|
||||
for idx, line in enumerate(stdoutLines):
|
||||
if re.match(r'data:image/\w+;base64', line):
|
||||
image_url = get_image_url_from_base64(
|
||||
image_url = await get_image_url_from_base64(
|
||||
request,
|
||||
line,
|
||||
metadata,
|
||||
@@ -4558,7 +4559,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
resultLines = result.split('\n')
|
||||
for idx, line in enumerate(resultLines):
|
||||
if re.match(r'data:image/\w+;base64', line):
|
||||
image_url = get_image_url_from_base64(
|
||||
image_url = await get_image_url_from_base64(
|
||||
request,
|
||||
line,
|
||||
metadata,
|
||||
@@ -4623,7 +4624,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
if item.get('status') == 'in_progress':
|
||||
item['status'] = 'completed'
|
||||
|
||||
title = Chats.get_chat_title_by_id(metadata['chat_id'])
|
||||
title = await Chats.get_chat_title_by_id(metadata['chat_id'])
|
||||
data = {
|
||||
'done': True,
|
||||
'content': serialize_output(output),
|
||||
@@ -4634,7 +4635,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
|
||||
if not ENABLE_REALTIME_CHAT_SAVE:
|
||||
# Save message in the database
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -4645,21 +4646,21 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
},
|
||||
)
|
||||
elif usage:
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{'done': True, 'usage': usage},
|
||||
)
|
||||
else:
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{'done': True},
|
||||
)
|
||||
|
||||
# Send a webhook notification if the user is not active
|
||||
if request.app.state.config.ENABLE_USER_WEBHOOKS and not Users.is_user_active(user.id):
|
||||
webhook_url = Users.get_user_webhook_url_by_id(user.id)
|
||||
if request.app.state.config.ENABLE_USER_WEBHOOKS and not await Users.is_user_active(user.id):
|
||||
webhook_url = await Users.get_user_webhook_url_by_id(user.id)
|
||||
if webhook_url:
|
||||
await post_webhook(
|
||||
request.app.state.WEBUI_NAME,
|
||||
@@ -4687,7 +4688,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
|
||||
if not ENABLE_REALTIME_CHAT_SAVE:
|
||||
# Save message in the database
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{
|
||||
@@ -4697,7 +4698,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
},
|
||||
)
|
||||
else:
|
||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
await Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||
metadata['chat_id'],
|
||||
metadata['message_id'],
|
||||
{'done': True},
|
||||
|
||||
Reference in New Issue
Block a user