refac
This commit is contained in:
@@ -583,7 +583,7 @@ from open_webui.tasks import (
|
|||||||
from open_webui.utils.redis import get_sentinels_from_env
|
from open_webui.utils.redis import get_sentinels_from_env
|
||||||
|
|
||||||
|
|
||||||
from open_webui.constants import ERROR_MESSAGES
|
from open_webui.constants import ERROR_MESSAGES, TASKS
|
||||||
|
|
||||||
if SAFE_MODE:
|
if SAFE_MODE:
|
||||||
print('SAFE MODE ENABLED')
|
print('SAFE MODE ENABLED')
|
||||||
@@ -1827,7 +1827,7 @@ async def chat_completion(
|
|||||||
detail=str(e),
|
detail=str(e),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def process_chat(request, form_data, user, metadata, model):
|
async def process_chat(request, form_data, user, metadata, model, tasks=None):
|
||||||
try:
|
try:
|
||||||
form_data, metadata, events = await process_chat_payload(request, form_data, user, metadata, model)
|
form_data, metadata, events = await process_chat_payload(request, form_data, user, metadata, model)
|
||||||
|
|
||||||
@@ -1931,7 +1931,7 @@ async def chat_completion(
|
|||||||
task_ids = []
|
task_ids = []
|
||||||
chat_id = metadata['chat_id']
|
chat_id = metadata['chat_id']
|
||||||
|
|
||||||
for target_model_id, assistant_message_id in message_ids.items():
|
for idx, (target_model_id, assistant_message_id) in enumerate(message_ids.items()):
|
||||||
if not assistant_message_id:
|
if not assistant_message_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -1951,9 +1951,17 @@ async def chat_completion(
|
|||||||
# Resolve the model object for this specific model
|
# Resolve the model object for this specific model
|
||||||
resolved_model = request.app.state.MODELS.get(target_model_id, model)
|
resolved_model = request.app.state.MODELS.get(target_model_id, model)
|
||||||
|
|
||||||
|
# Only the first model runs title/tags generation;
|
||||||
|
# subsequent models only run follow-ups.
|
||||||
task_id, _ = await create_task(
|
task_id, _ = await create_task(
|
||||||
request.app.state.redis,
|
request.app.state.redis,
|
||||||
process_chat(request, model_form_data, user, per_model_metadata, resolved_model),
|
process_chat(
|
||||||
|
request, model_form_data, user, per_model_metadata, resolved_model,
|
||||||
|
tasks if idx == 0 else {
|
||||||
|
k: v for k, v in (tasks or {}).items()
|
||||||
|
if k not in (TASKS.TITLE_GENERATION, TASKS.TAGS_GENERATION)
|
||||||
|
} or None,
|
||||||
|
),
|
||||||
id=chat_id,
|
id=chat_id,
|
||||||
)
|
)
|
||||||
task_ids.append(task_id)
|
task_ids.append(task_id)
|
||||||
@@ -1975,7 +1983,7 @@ async def chat_completion(
|
|||||||
else:
|
else:
|
||||||
# Legacy/direct: single model, synchronous
|
# Legacy/direct: single model, synchronous
|
||||||
metadata['message_id'] = list(message_ids.values())[0]
|
metadata['message_id'] = list(message_ids.values())[0]
|
||||||
return await process_chat(request, form_data, user, metadata, model)
|
return await process_chat(request, form_data, user, metadata, model, tasks)
|
||||||
|
|
||||||
|
|
||||||
# Alias for chat_completion (Legacy)
|
# Alias for chat_completion (Legacy)
|
||||||
|
|||||||
@@ -2345,11 +2345,8 @@
|
|||||||
|
|
||||||
background_tasks: {
|
background_tasks: {
|
||||||
...(!$temporaryChatEnabled &&
|
...(!$temporaryChatEnabled &&
|
||||||
(messages.length == 1 ||
|
!_chatId &&
|
||||||
(messages.length == 2 &&
|
(userMessage?.parentId ?? null) === null
|
||||||
messages.at(0)?.role === 'system' &&
|
|
||||||
messages.at(1)?.role === 'user')) &&
|
|
||||||
(selectedModels[0] === model.id || atSelectedModel !== undefined)
|
|
||||||
? {
|
? {
|
||||||
title_generation: $settings?.title?.auto ?? true,
|
title_generation: $settings?.title?.auto ?? true,
|
||||||
tags_generation: $settings?.autoTags ?? true
|
tags_generation: $settings?.autoTags ?? true
|
||||||
|
|||||||
Reference in New Issue
Block a user