mirror of
https://github.com/open-webui/open-webui
synced 2024-11-07 00:59:52 +00:00
refac
This commit is contained in:
parent
52cae406b4
commit
d97a4d687e
@ -1123,6 +1123,17 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
|
||||
else:
|
||||
pass
|
||||
|
||||
async def __event_emitter__(data):
|
||||
await sio.emit(
|
||||
"chat-events",
|
||||
{
|
||||
"chat_id": data["chat_id"],
|
||||
"message_id": data["id"],
|
||||
"data": data,
|
||||
},
|
||||
to=data["session_id"],
|
||||
)
|
||||
|
||||
def get_priority(function_id):
|
||||
function = Functions.get_function_by_id(function_id)
|
||||
if function is not None and hasattr(function, "valves"):
|
||||
@ -1204,6 +1215,12 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
|
||||
"__model__": model,
|
||||
}
|
||||
|
||||
if "__event_emitter__" in sig.parameters:
|
||||
params = {
|
||||
**params,
|
||||
"__event_emitter__": __event_emitter__,
|
||||
}
|
||||
|
||||
if inspect.iscoroutinefunction(outlet):
|
||||
data = await outlet(**params)
|
||||
else:
|
||||
|
@ -327,7 +327,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
const chatCompletedHandler = async (modelId, messages) => {
|
||||
const chatCompletedHandler = async (modelId, responseMessageId, messages) => {
|
||||
await mermaid.run({
|
||||
querySelector: '.mermaid'
|
||||
});
|
||||
@ -341,7 +341,9 @@
|
||||
info: m.info ? m.info : undefined,
|
||||
timestamp: m.timestamp
|
||||
})),
|
||||
chat_id: $chatId
|
||||
chat_id: $chatId,
|
||||
session_id: $socket?.id,
|
||||
id: responseMessageId
|
||||
}).catch((error) => {
|
||||
toast.error(error);
|
||||
messages.at(-1).error = { content: error };
|
||||
@ -731,7 +733,7 @@
|
||||
controller.abort('User: Stop Response');
|
||||
} else {
|
||||
const messages = createMessagesList(responseMessageId);
|
||||
await chatCompletedHandler(model.id, messages);
|
||||
await chatCompletedHandler(model.id, responseMessageId, messages);
|
||||
}
|
||||
|
||||
_response = responseMessage.content;
|
||||
@ -1041,7 +1043,7 @@
|
||||
} else {
|
||||
const messages = createMessagesList(responseMessageId);
|
||||
|
||||
await chatCompletedHandler(model.id, messages);
|
||||
await chatCompletedHandler(model.id, responseMessageId, messages);
|
||||
}
|
||||
|
||||
_response = responseMessage.content;
|
||||
|
Loading…
Reference in New Issue
Block a user