diff --git a/backend/open_webui/utils/chat.py b/backend/open_webui/utils/chat.py index 5ce6fffec..9a9e81033 100644 --- a/backend/open_webui/utils/chat.py +++ b/backend/open_webui/utils/chat.py @@ -316,6 +316,10 @@ async def chat_completed(request: Request, form_data: dict, user: Any): models = request.app.state.MODELS data = form_data + + if not data.get('id'): + raise Exception('Missing message id') + model_id = data['model'] if model_id not in models: raise Exception('Model not found') @@ -327,6 +331,9 @@ async def chat_completed(request: Request, form_data: dict, user: Any): except Exception as e: raise Exception(f'Error: {e}') + if not data.get('id'): + raise Exception('Missing message id') + metadata = { 'chat_id': data['chat_id'], 'message_id': data['id'], diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index c46c86b80..fea2d3899 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -161,9 +161,12 @@ export const getModels = async ( type ChatCompletedForm = { model: string; - messages: string[]; + messages: Record[]; chat_id: string; - session_id: string; + session_id: string | undefined; + id: string; + filter_ids?: string[]; + model_item?: unknown; }; export const chatCompleted = async (token: string, body: ChatCompletedForm) => { diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index c82bb55fd..c3864bc74 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1358,6 +1358,11 @@ }; const chatCompletedHandler = async (_chatId, modelId, responseMessageId, messages) => { + if (!responseMessageId) { + console.error('chatCompleted: missing message id', { chatId: _chatId, modelId, messageCount: messages?.length ?? 0 }); + return; + } + const res = await chatCompleted(localStorage.token, { model: modelId, messages: messages.map((m) => ({