This commit is contained in:
Timothy J. Baek 2024-07-01 21:41:44 -07:00
parent 52cae406b4
commit d97a4d687e
2 changed files with 23 additions and 4 deletions

View File

@ -1123,6 +1123,17 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
else: else:
pass 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): def get_priority(function_id):
function = Functions.get_function_by_id(function_id) function = Functions.get_function_by_id(function_id)
if function is not None and hasattr(function, "valves"): 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, "__model__": model,
} }
if "__event_emitter__" in sig.parameters:
params = {
**params,
"__event_emitter__": __event_emitter__,
}
if inspect.iscoroutinefunction(outlet): if inspect.iscoroutinefunction(outlet):
data = await outlet(**params) data = await outlet(**params)
else: else:

View File

@ -327,7 +327,7 @@
} }
}; };
const chatCompletedHandler = async (modelId, messages) => { const chatCompletedHandler = async (modelId, responseMessageId, messages) => {
await mermaid.run({ await mermaid.run({
querySelector: '.mermaid' querySelector: '.mermaid'
}); });
@ -341,7 +341,9 @@
info: m.info ? m.info : undefined, info: m.info ? m.info : undefined,
timestamp: m.timestamp timestamp: m.timestamp
})), })),
chat_id: $chatId chat_id: $chatId,
session_id: $socket?.id,
id: responseMessageId
}).catch((error) => { }).catch((error) => {
toast.error(error); toast.error(error);
messages.at(-1).error = { content: error }; messages.at(-1).error = { content: error };
@ -731,7 +733,7 @@
controller.abort('User: Stop Response'); controller.abort('User: Stop Response');
} else { } else {
const messages = createMessagesList(responseMessageId); const messages = createMessagesList(responseMessageId);
await chatCompletedHandler(model.id, messages); await chatCompletedHandler(model.id, responseMessageId, messages);
} }
_response = responseMessage.content; _response = responseMessage.content;
@ -1041,7 +1043,7 @@
} else { } else {
const messages = createMessagesList(responseMessageId); const messages = createMessagesList(responseMessageId);
await chatCompletedHandler(model.id, messages); await chatCompletedHandler(model.id, responseMessageId, messages);
} }
_response = responseMessage.content; _response = responseMessage.content;