chore: format
This commit is contained in:
1 parent
0037baeb26
commit
4856ce48be
4 files changed
+26
-15
No files matched your search
@@ -1796,7 +1796,9 @@ async def chat_completion(
|
|||||||
|
|
||||||
if metadata.get('chat_id') and user:
|
if metadata.get('chat_id') and user:
|
||||||
chat_id = metadata['chat_id']
|
chat_id = metadata['chat_id']
|
||||||
if not chat_id.startswith('local:') and not chat_id.startswith('channel:'): # temporary/channel chats are not stored
|
if not chat_id.startswith('local:') and not chat_id.startswith(
|
||||||
|
'channel:'
|
||||||
|
): # temporary/channel chats are not stored
|
||||||
if is_new_chat:
|
if is_new_chat:
|
||||||
# Build the full history upfront with ALL assistant placeholders
|
# Build the full history upfront with ALL assistant placeholders
|
||||||
user_message = metadata.get('user_message') or {}
|
user_message = metadata.get('user_message') or {}
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ from open_webui.utils.models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||||
from open_webui.utils.access_control import has_permission, filter_allowed_access_grants
|
from open_webui.utils.access_control import has_permission, filter_allowed_access_grants
|
||||||
from open_webui.utils.webhook import post_webhook
|
from open_webui.utils.webhook import post_webhook
|
||||||
@@ -1017,9 +1016,7 @@ async def model_response_handler(request, channel, message, user, db=None):
|
|||||||
# tools, filters, RAG — everything. The pipeline runs as
|
# tools, filters, RAG — everything. The pipeline runs as
|
||||||
# an async task; the channel emitter handles progressive
|
# an async task; the channel emitter handles progressive
|
||||||
# message updates via socket events.
|
# message updates via socket events.
|
||||||
await request.app.state.CHAT_COMPLETION_HANDLER(
|
await request.app.state.CHAT_COMPLETION_HANDLER(request, form_data, user=user)
|
||||||
request, form_data, user=user
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
|||||||
@@ -891,11 +891,7 @@ async def _make_channel_emitter(request_info):
|
|||||||
|
|
||||||
elif event_type == 'chat:message:error':
|
elif event_type == 'chat:message:error':
|
||||||
error = event_data.get('data', {}).get('error', {})
|
error = event_data.get('data', {}).get('error', {})
|
||||||
error_content = (
|
error_content = error.get('content', 'An error occurred') if isinstance(error, dict) else str(error)
|
||||||
error.get('content', 'An error occurred')
|
|
||||||
if isinstance(error, dict)
|
|
||||||
else str(error)
|
|
||||||
)
|
|
||||||
await _emit_channel_update(f'Error: {error_content}', done=True)
|
await _emit_channel_update(f'Error: {error_content}', done=True)
|
||||||
|
|
||||||
return __channel_emitter__
|
return __channel_emitter__
|
||||||
|
|||||||
@@ -3058,7 +3058,11 @@ async def background_tasks_handler(ctx):
|
|||||||
message = None
|
message = None
|
||||||
messages = []
|
messages = []
|
||||||
|
|
||||||
if 'chat_id' in metadata and not metadata['chat_id'].startswith('local:') and not metadata['chat_id'].startswith('channel:'):
|
if (
|
||||||
|
'chat_id' in metadata
|
||||||
|
and not metadata['chat_id'].startswith('local:')
|
||||||
|
and not metadata['chat_id'].startswith('channel:')
|
||||||
|
):
|
||||||
messages_map = await 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 = messages_map.get(metadata['message_id']) if messages_map else None
|
||||||
|
|
||||||
@@ -3138,7 +3142,9 @@ async def background_tasks_handler(ctx):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if not metadata.get('chat_id', '').startswith('local:') and not metadata.get('chat_id', '').startswith('channel:'):
|
if not metadata.get('chat_id', '').startswith('local:') and not metadata.get(
|
||||||
|
'chat_id', ''
|
||||||
|
).startswith('channel:'):
|
||||||
await 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['chat_id'],
|
||||||
metadata['message_id'],
|
metadata['message_id'],
|
||||||
@@ -3150,7 +3156,9 @@ async def background_tasks_handler(ctx):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not metadata.get('chat_id', '').startswith('local:') and not metadata.get('chat_id', '').startswith('channel:'): # Only update titles and tags for non-temp chats
|
if not metadata.get('chat_id', '').startswith('local:') and not metadata.get('chat_id', '').startswith(
|
||||||
|
'channel:'
|
||||||
|
): # Only update titles and tags for non-temp chats
|
||||||
if TASKS.TITLE_GENERATION in tasks:
|
if TASKS.TITLE_GENERATION in tasks:
|
||||||
user_message = get_last_user_message(messages)
|
user_message = get_last_user_message(messages)
|
||||||
if user_message and len(user_message) > 100:
|
if user_message and len(user_message) > 100:
|
||||||
@@ -3453,7 +3461,11 @@ async def non_streaming_chat_response_handler(response, ctx):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
title = await Chats.get_chat_title_by_id(metadata['chat_id']) if not metadata['chat_id'].startswith('channel:') else ''
|
title = (
|
||||||
|
await Chats.get_chat_title_by_id(metadata['chat_id'])
|
||||||
|
if not metadata['chat_id'].startswith('channel:')
|
||||||
|
else ''
|
||||||
|
)
|
||||||
|
|
||||||
# Use output from backend if provided (OR-compliant backends),
|
# Use output from backend if provided (OR-compliant backends),
|
||||||
# otherwise generate from response content
|
# otherwise generate from response content
|
||||||
@@ -5026,7 +5038,11 @@ async def streaming_chat_response_handler(response, ctx):
|
|||||||
if item.get('status') == 'in_progress':
|
if item.get('status') == 'in_progress':
|
||||||
item['status'] = 'completed'
|
item['status'] = 'completed'
|
||||||
|
|
||||||
title = await Chats.get_chat_title_by_id(metadata['chat_id']) if not metadata['chat_id'].startswith('channel:') else ''
|
title = (
|
||||||
|
await Chats.get_chat_title_by_id(metadata['chat_id'])
|
||||||
|
if not metadata['chat_id'].startswith('channel:')
|
||||||
|
else ''
|
||||||
|
)
|
||||||
data = {
|
data = {
|
||||||
'done': True,
|
'done': True,
|
||||||
'content': serialize_output(output),
|
'content': serialize_output(output),
|
||||||
|
|||||||
Reference in new issue
Block a user