fix: guard completed API with message id (#23184)
This commit is contained in:
@@ -316,6 +316,10 @@ async def chat_completed(request: Request, form_data: dict, user: Any):
|
|||||||
models = request.app.state.MODELS
|
models = request.app.state.MODELS
|
||||||
|
|
||||||
data = form_data
|
data = form_data
|
||||||
|
|
||||||
|
if not data.get('id'):
|
||||||
|
raise Exception('Missing message id')
|
||||||
|
|
||||||
model_id = data['model']
|
model_id = data['model']
|
||||||
if model_id not in models:
|
if model_id not in models:
|
||||||
raise Exception('Model not found')
|
raise Exception('Model not found')
|
||||||
@@ -327,6 +331,9 @@ async def chat_completed(request: Request, form_data: dict, user: Any):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f'Error: {e}')
|
raise Exception(f'Error: {e}')
|
||||||
|
|
||||||
|
if not data.get('id'):
|
||||||
|
raise Exception('Missing message id')
|
||||||
|
|
||||||
metadata = {
|
metadata = {
|
||||||
'chat_id': data['chat_id'],
|
'chat_id': data['chat_id'],
|
||||||
'message_id': data['id'],
|
'message_id': data['id'],
|
||||||
|
|||||||
@@ -161,9 +161,12 @@ export const getModels = async (
|
|||||||
|
|
||||||
type ChatCompletedForm = {
|
type ChatCompletedForm = {
|
||||||
model: string;
|
model: string;
|
||||||
messages: string[];
|
messages: Record<string, unknown>[];
|
||||||
chat_id: string;
|
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) => {
|
export const chatCompleted = async (token: string, body: ChatCompletedForm) => {
|
||||||
|
|||||||
@@ -1358,6 +1358,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const chatCompletedHandler = async (_chatId, modelId, responseMessageId, messages) => {
|
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, {
|
const res = await chatCompleted(localStorage.token, {
|
||||||
model: modelId,
|
model: modelId,
|
||||||
messages: messages.map((m) => ({
|
messages: messages.map((m) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user