Skip to content

Commit d7a5a90

Browse files
fix: guard completed API with message id (open-webui#23184)
1 parent 16e6cb4 commit d7a5a90

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

backend/open_webui/utils/chat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ async def chat_completed(request: Request, form_data: dict, user: Any):
316316
models = request.app.state.MODELS
317317

318318
data = form_data
319+
320+
if not data.get('id'):
321+
raise Exception('Missing message id')
322+
319323
model_id = data['model']
320324
if model_id not in models:
321325
raise Exception('Model not found')
@@ -327,6 +331,9 @@ async def chat_completed(request: Request, form_data: dict, user: Any):
327331
except Exception as e:
328332
raise Exception(f'Error: {e}')
329333

334+
if not data.get('id'):
335+
raise Exception('Missing message id')
336+
330337
metadata = {
331338
'chat_id': data['chat_id'],
332339
'message_id': data['id'],

src/lib/apis/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,12 @@ export const getModels = async (
161161

162162
type ChatCompletedForm = {
163163
model: string;
164-
messages: string[];
164+
messages: Record<string, unknown>[];
165165
chat_id: string;
166-
session_id: string;
166+
session_id: string | undefined;
167+
id: string;
168+
filter_ids?: string[];
169+
model_item?: unknown;
167170
};
168171

169172
export const chatCompleted = async (token: string, body: ChatCompletedForm) => {

src/lib/components/chat/Chat.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,11 @@
13581358
};
13591359
13601360
const chatCompletedHandler = async (_chatId, modelId, responseMessageId, messages) => {
1361+
if (!responseMessageId) {
1362+
console.error('chatCompleted: missing message id', { chatId: _chatId, modelId, messageCount: messages?.length ?? 0 });
1363+
return;
1364+
}
1365+
13611366
const res = await chatCompleted(localStorage.token, {
13621367
model: modelId,
13631368
messages: messages.map((m) => ({

0 commit comments

Comments
 (0)