This commit is contained in:
Timothy J. Baek 2024-07-11 19:05:59 -07:00
parent 14c0efe300
commit 856845e5f2
4 changed files with 35 additions and 10 deletions

View File

@ -363,7 +363,7 @@
}
};
const chatCompletedHandler = async (modelId, responseMessageId, messages) => {
const chatCompletedHandler = async (chatId, modelId, responseMessageId, messages) => {
await mermaid.run({
querySelector: '.mermaid'
});
@ -377,7 +377,7 @@
info: m.info ? m.info : undefined,
timestamp: m.timestamp
})),
chat_id: $chatId,
chat_id: chatId,
session_id: $socket?.id,
id: responseMessageId
}).catch((error) => {
@ -399,9 +399,21 @@
};
}
}
if ($chatId == chatId) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, chatId, {
models: selectedModels,
messages: messages,
history: history,
params: params
});
await chats.set(await getChatList(localStorage.token));
}
}
};
const chatActionHandler = async (actionId, modelId, responseMessageId) => {
const chatActionHandler = async (chatId, actionId, modelId, responseMessageId) => {
const res = await chatAction(localStorage.token, actionId, {
model: modelId,
messages: messages.map((m) => ({
@ -411,7 +423,7 @@
info: m.info ? m.info : undefined,
timestamp: m.timestamp
})),
chat_id: $chatId,
chat_id: chatId,
session_id: $socket?.id,
id: responseMessageId
}).catch((error) => {
@ -432,6 +444,18 @@
};
}
}
if ($chatId == chatId) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, chatId, {
models: selectedModels,
messages: messages,
history: history,
params: params
});
await chats.set(await getChatList(localStorage.token));
}
}
};
const getChatEventEmitter = async (modelId: string, chatId: string = '') => {
@ -801,7 +825,7 @@
controller.abort('User: Stop Response');
} else {
const messages = createMessagesList(responseMessageId);
await chatCompletedHandler(model.id, responseMessageId, messages);
await chatCompletedHandler(_chatId, model.id, responseMessageId, messages);
}
_response = responseMessage.content;
@ -1113,7 +1137,7 @@
} else {
const messages = createMessagesList(responseMessageId);
await chatCompletedHandler(model.id, responseMessageId, messages);
await chatCompletedHandler(_chatId, model.id, responseMessageId, messages);
}
_response = responseMessage.content;

View File

@ -336,7 +336,9 @@
copyToClipboard={copyToClipboardWithToast}
{continueGeneration}
{regenerateResponse}
{chatActionHandler}
on:action={async (e) => {
await chatActionHandler(chatId, e.detail, message.model, message.id);
}}
on:save={async (e) => {
console.log('save', e);

View File

@ -1031,8 +1031,7 @@
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition regenerate-response-button"
on:click={() => {
chatActionHandler(action.id, message.model, message.id);
console.log('action');
dispatch('action', action.id);
}}
>
<Sparkles strokeWidth="2.1" className="size-4" />